p. 1
developer s guide lightweight ui toolkit sun microsystems inc www.sun.com part no 07-2009 july 2009 submit comments about this document to lwuit@sun.com
[close]
p. 2
copyright © 2009 sun microsystems inc 4150 network circle santa clara california 95054 u.s.a all rights reserved sun microsystems inc has intellectual property rights relating to technology embodied in the product that is described in this document in particular and without limitation these intellectual property rights may include one or more of the u.s patents listed at http www.sun.com/patents and one or more additional patents or pending patent applications in the u.s and in other countries u.s government rights commercial software government users are subject to the sun microsystems inc standard license agreement and applicable provisions of the far and its supplements use is subject to license terms this distribution may include materials developed by third parties sun sun microsystems the sun logo java jar java se java me netbeans java and the java coffee cup logo are trademarks or registered trademarks of sun microsystems inc in the u.s and other countries the adobe logo is a registered trademark of adobe systems incorporated sprint the going forward logo and other trademarks are trademarks of sprint nextel this product is covered and controlled by u.s export control laws and may be subject to the export or import laws in other countries nuclear missile chemical biological weapons or nuclear maritime end uses or end users whether direct or indirect are strictly prohibited export or reexport to countries subject to u.s embargo or to entities identified on u.s export exclusion lists including but not limited to the denied persons and specially designated nationals lists is strictly prohibited copyright © 2009 sun microsystems inc 4150 network circle santa clara california 95054 etats-unis tous droits réservés sun microsystems inc détient les droits de propriété intellectuels relatifs à la technologie incorporée dans le produit qui est décrit dans ce document en particulier et ce sans limitation ces droits de propriété intellectuelle peuvent inclure un ou plus des brevets américains listés à l adresse http www.sun.com/patents et un ou les brevets supplémentaires ou les applications de brevet en attente aux etats unis et dans les autres pays l utilisation est soumise aux termes de la licence cette distribution peut comprendre des composants développés par des tierces parties sun sun microsystems le logo sun java jar java se java me netbeans java et le logo java coffee cup sont des marques de fabrique ou des marques déposées de sun microsystems inc aux etats-unis et dans d autres pays le logo adobe est une marque déposée de adobe systems incorporated sprint the going forward logo and other trademarks are trademarks of sprint nextel ce produit est soumis à la législation américaine en matière de contrôle des exportations et peut être soumis à la règlementation en vigueur dans d autres pays dans le domaine des exportations et importations les utilisations ou utilisateurs finaux pour des armes nucléaires,des missiles des armes biologiques et chimiques ou du nucléaire maritime directement ou indirectement sont strictement interdites les exportations ou réexportations vers les pays sous embargo américain ou vers des entités figurant sur les listes d exclusion d exportation américaines y compris mais de manière non exhaustive la liste de personnes qui font objet d un ordre de ne pas participer d une façon directe ou indirecte aux exportations des produits ou des services qui sont régis par la législation américaine en matière de contrôle des exportations et la liste de ressortissants spécifiquement désignés sont rigoureusement interdites.
[close]
p. 3
contents preface 1 ix 11 introducing the lightweight ui toolkit library 1.1 api overview 1.1.1 1.1.2 11 12 14 21 scope and portability events and threading 2 using lightweight ui toolkit widgets 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 2.10 2.11 component container form label button 22 23 25 26 27 21 21 radiobutton buttongroup checkbox combobox textarea 28 210 212 213 tabbedpane 31 3 using lists iii
[close]
p. 4
3.1 3.2 initializing a list creating a model 3.2.1 3.2.2 listmodel 31 32 32 32 defaultlistmodel 33 3.3 list cell renderer 3.3.1 3.3.2 listcellrenderer 33 34 34 defaultlistcellrenderer 3.4 3.5 adding items to and removing items from a list list events 3.5.1 3.5.2 35 35 fixed selection feature smooth scrolling 41 41 42 36 4 using dialogs 4.1 4.2 dialog types creating a dialog 4.2.1 4.2.2 4.2.3 4.2.4 return types of show methods non-static show methods 44 43 using the dispose method 44 44 getting the user s input from a dialog 51 5 using layout managers 5.1 5.2 borderlayout boxlayout 5.2.1 5.2.2 5.3 5.4 5.5 51 53 53 54 x_axis y_axis 54 56 flowlayout gridlayout grouplayout 61 57 6 using painters iv lightweight ui toolkit developer s guide · july 2009
[close]
p. 5
7 using the style object 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 color font 71 72 71 transparency 72 72 margin and padding images borders 73 74 74 style listener painters 81 74 8 theming 8.1 8.2 basic theming look and feel 91 81 84 9 resources 9.1 9.2 introduction 91 91 92 92 92 resource elements 9.2.1 building a bundle 9.2.1.1 9.2.1.2 creating a resource loading a resource 92 93 9.2.2 9.2.3 9.2.4 image resources indexed images fonts 9.2.4.1 9.2.4.2 94 system font 94 95 dynamic fonts 96 9.2.5 9.2.6 9.3 localization l10n themes 96 97 the lwuit designer 9.3.1 images and animations 99 contents v
[close]
p. 6
9.3.2 9.3.3 9.3.4 fonts 910 911 localization themes 9.3.4.1 9.3.4.2 9.3.4.3 9.3.4.4 9.3.4.5 912 example adding a new theme modifying theme properties data 915 915 912 914 customizing the preview known issues 917 10 using transitions and animations 10.1 10.2 10.3 animation motion 101 101 101 102 102 104 transition 10.3.1 10.3.2 slide transition fade transition 11 12 using 3d logging 12.1 12.2 111 121 121 122 131 writing to a log showing the log 13 authoring components 13.1 13.2 13.3 13.4 13.5 13.6 13.7 introduction painting 131 132 133 134 sizing in layout event handling focus 134 the painting pipeline styling 135 135 vi lightweight ui toolkit developer s guide · july 2009
[close]
p. 7
13.8 13.9 background 137 138 animating the component 13.10 the custom component 14 portability and performance 14.1 14.2 introduction performance 14.2.1 141 142 142 1310 141 memory 14.2.1.1 14.2.1.2 indexed images light mode 144 142 144 14.2.2 speed 14.2.2.1 14.2.2.2 event dispatch thread edt lwuit performance 145 145 144 14.3 device bugs and limitations 14.3.1 14.3.2 bugs 145 146 limitations 14.4 14.5 resolution independence input 14.5.1 14.5.2 14.5.3 148 soft buttons back button 148 148 147 touch screen devices 149 148 14.6 specific device issues 14.6.1 14.6.2 14.6.3 14.6.4 14.6.5 motorola blackberry nokia s40 149 149 1410 1410 1410 sony ericsson general portability tip a1 a lwuit mini faq contents vii
[close]
p. 8
index index1 viii lightweight ui toolkit developer s guide · july 2009
[close]
p. 9
preface this document describes how to work with the lightweight user interface toolkit before you read this document this guide is intended for developers creating mobile information device profile midp applications this book is a tutorial in lightweight ui toolkit programming over midp you should already have basic knowledge about javatm ui libraries for example awt and swing and understand how to use the mobile information device profile midp and the connected limited device configuration cldc for current discussion of lwuit issues see these online resources lwuit home page https lwuit.dev.java.net lwuit community discussion forum http forums.java.net.jive/form.jspa?forumid=139 lwuit blog http lwuit.blogspot.com if you need help getting started with the java programming language try the new to java center http java.sun.com/learning/new2java for a quick start with midp programming read learning path getting started with midp 2.0 http developers.sun.com/techtopics/mobility/learn/midp/midp20 the following sites provide technical documentation related to java technology http developers.sun.com ix
[close]
p. 10
http java.sun.com/javame how this document is organized this guide contains the following chapters and appendices chapter 1 introduces the lightweight ui toolkit library chapter 2 describes how to use lightweight ui toolkit widgets chapter 3 explains how to use lists chapter 4 describes how to use dialogs chapter 5 shows how you can use layouts chapter 6 describes how to use images chapter 7 details how to use fonts chapter 6 explains how to use painters chapter 7 explains how to use style chapter 8 describes themes chapter 9 describes the lwuit designer chapter 10 describes how to use transitions and animations chapter 11 covers the 3d integration chapter 12 details how to use logging chapter 13 describes how to author a new component from scratch chapter 14 discusses general and device-specific portability issues appendix a addresses frequently asked questions about lwuit x lightweight ui toolkit developer s guide · july 2009
[close]
p. 11
shell prompts shell prompt c shell c shell superuser bourne shell and korn shell bourne shell and korn shell superuser machine-name machine-name typographic conventions typeface meaning examples aabbcc123 the names of commands files and directories on-screen computer output what you type when contrasted with on-screen computer output book titles new words or terms words to be emphasized replace command-line variables with real names or values edit your.login file use ls -a to list all files you have mail su password read chapter 6 in the user s guide these are called class options you must be superuser to do this to delete a file type rm filename aabbcc123 aabbcc123 note characters display differently depending on browser settings if characters do not display correctly change the character encoding in your browser to unicode utf-8 preface xi
[close]
p. 12
related documentation table p-1 lists documentation related to this product table p-1 topic recommended documentation title and url jsr 118 midp 2.0 jsr 139 cldc 1.1 jsr 184 3d graphics awt documentation mobile information device profile http jcp.org/en/jsr/detail?id=118 connected limited device configuration http jcp.org/en/jsr/detail?id=139 mobile 3d graphics api for j2me http jcp.org/en/jsr/detail?id=184 http java.sun.com/javase/6/docs/technotes/guides /awt/index.html swing documentation http java.sun.com/javase/6/docs/technotes/guides /swing/index.html http java.sun.com/docs/books/tutorial/uiswing sun welcomes your comments sun is interested in improving our documentation and welcomes your comments and suggestions email your feedback to lwuit@sun.com xii lightweight ui toolkit developer s guide · july 2009
[close]
p. 13
chapter 1 introducing the lightweight ui toolkit library this book describes how to use the lightweight ui toolkit lwuit library the lightweight ui toolkit library helps you create appealing graphical user interface gui applications for mobile phones and other devices that support midp 2.0 lightweight ui toolkit supports visual components and other user interface ui ingredients such as theming transitions animation and more after covering the basics of the lightweight ui toolkit this book provides a walk through of the various widgets and uses of the lwuit packages 1.1 api overview the lightweight ui toolkit is a lightweight widget library inspired by swing but designed for constrained devices such as mobile phones and set-top boxes lightweight ui toolkit supports pluggable theme-ability a component and container hierarchy and abstraction of the underlying gui toolkit the term lightweight indicates that the widgets in the library draw their state in java source without native peer rendering internal interfaces and abstract classes provide abstraction of interfaces and apis in the underlying profile this allows portability and a migration path for both current and future devices and profiles for example graphics would be an abstraction of the graphics object in the underlying profile the lightweight ui toolkit library tries to avoid the lowest common denominator mentality by implementing some features missing in the low-end platforms and taking better advantage of high-end platforms figure 1-1 shows the widget class hierarchy 1-1
[close]
p. 14
figure 1-1 simplified widget class hierarchy 1.1.1 scope and portability the lightweight ui toolkit library is strictly a widget ui library and does not try to abstract the underlying system services such as networking or storage it also doesn t try to solve other ui issues related to native graphics etcetera to enable portability the lightweight ui toolkit library implements its own thin layer on top of the native system canvas and provides a widget abstraction this abstraction is achieved using several key classes that hide the system specific equivalents to said classes such as graphics image and font when working with the lightweight ui toolkit library it is critical to use the abstract classes for everything to avoid corruption there is no way to access the real underlying instances of these classes for example javax.microedition.lwuit.graphics lwuit strives to enable great functionality on small devices that might be incapable of anti-aliasing at runtime or might choke under the weight of many images to solve these problems the lwuit library ships with an optional resource file format that improves resource utilization for more details see chapter 9 resources example 1-1 hello world example for midp this is a simple hello world example written on top of midp all ui code making use of the lightweight ui toolkit is compatible to other platforms such as cdc.1 1-2 lightweight ui toolkit developer s guide · july 2009
[close]
p. 15
however this example is specifically for midp for midp the application management system ams requires a midlet class to exist where in a cdc environment an xlet would be expected and in javatm se you would expect a main class and so forth import import import import import import com.sun.lwuit.display com.sun.lwuit.form com.sun.lwuit.label com.sun.lwuit.layouts.borderlayout com.sun.lwuit.plaf.uimanager com.sun.lwuit.util.resources public class hellomidlet extends javax.microedition.midlet.midlet public void startapp init the lwuit display display.initthis setting the application theme is discussed later in the theme chapter and the resources chapter try resources r resources.open myresources.res uimanager.getinstance setthemepropsr.gettheme r.getthemeresourcenames 0 catch java.io.ioexception e form f new form f.settitle hello world f.setlayoutnew borderlayout f.addcomponent center new label i am a label f.show public void pauseapp public void destroyappboolean unconditional hello world looks like figure 1-2 1 as of this writing the cdc version of lwuit required for this compatibility hasn t been released to the public chapter 1 introducing the lightweight ui toolkit library 1-3
[close]