Beruflich Dokumente
Kultur Dokumente
慕 睿 涛 (Max.Mu@sun.com)
Sun Microsystems, Inc.
1
Goal
• Working practical knowledge of LWUIT
• Fun
4
The Big Fly-in
...and more!
Copyright © 2009 Sun Microsystems, Inc. All rights reserved. 5
The Big Fly-in
9
User Interface Choices: LCDUI
The Menu
• SVG
• 3D Graphics
• OpenGL ES
• LCDUI
and...
• LWUIT
OpenGL ES
• JSR 239, not part of
MSA 1.0
• OpenGL is a standard
API for 2D and 3D
graphics
• OpenGL ES is a subset
for mobile devices
• Close to the metal
LCDUI
• MIDP's user interface toolkit
• User interface from a can
> TextBox, Alert, List, Form
> Easy to use
> Generalized across devices, but...
> ...no guarantees about consistent user experience
• Do your own drawing with Canvas
> Caramba! Back to square one!
> Tricky to get this right
A Full Form
Command Examples
Command Placement
Sun toolkit RAZR Series 40 3rd edition
Canvas
• Do your own drawing
• Lines, rectangles, ellipses
• Limited fonts
• Limited image control
• It is possible to roll your own UI
toolkit this way
• Many application developers
take this route, but it’s tough
GameCanvas
• Extensions to Canvas for 2D games
• Streamlined animation pipeline
> Synchronous repainting
> Key polling
• Layers
• Sprites
> Animation
> Collisions
22
Ta-Dum!
Overview of LWUIT
• LightWeight User Interface Toolkit
• Looks great
• Highly portable
• Open source library
> GPL v2 with classpath exception
> http://lwuit.dev.java.net/
• Best of Swing
• Familiar APIs
• Built on MIDP 2.0, atop Canvas
Copyright © 2009 Sun Microsystems, Inc. All rights reserved. 23
Ta-Dum!
Clinchers
• Runs on many devices
• Transitions
• Layouts
• Fonts
• Themes
• Touch support
• Thriving community
• Can’t beat the price LWUITDemo
25
Digital TV Standards Worldwide
DTMS ACAP
CDC,PBP
Copyright © 2009 Sun Microsystems, Inc. All rights reserved. 26
CDC and PBP ties together the Java based TV
standards
CDC Market Coverage
Blu-ray Disc DTV/IPTV Cable DTV
Emerging:
IPTV,Brazil,
China
CDC,FP,PBP CDC,
FP,PBP
29
Hello, LWUIT!
• Initialize LWUIT
Display.init(this);
• Load a theme
> Sets colors, images, fonts
> More on this magic later
• Create a form
Form f = new Form("Hello, LWUIT!");
• Show the form
f.show();
HelloLWUIT
31
Using Form
• Create a form
Form f = new Form("Labels");
• Add some stuff
Label label = new Label("Baldy");
f.addComponent(label);
• Slap it up on the screen
f.show();
36
Partial Component Hierarchy
Component
ComponentMIDlet
showButtons()
showEvents()
Copyright © 2009 Sun Microsystems, Inc. All rights reserved. 39
RadioButton
• Inherits from Button
• Adds a boolean state
• Not much good by itself
• Use ButtonGroup
ComponentMIDlet
showMoreButtons()
ComponentMIDlet
showMoreButtons()
ComponentMIDlet
showText()
44
Lists
• Crucial for mobile applications
• MVC separation model
• Plenty of useful modes
> FIXED_NONE
> FIXED_NONE_CYCLIC
> FIXED_NONE_ONE_ELEMENT_MARGIN_FROM_EDGE
> FIXED_LEAD
> FIXED_TRAIL
> FIXED_CENTER
ListDemo
list1()
ListDemo
list5()
ListDemo
list6()
ComponentDemo
showListAndComboBox()
51
Dialog
• A Dialog is a Form that occupies a part of the
screen as a top component.
• Dialog can be modal/modalless
• Use show() or dispose() methods
• Two ways to create:
> Static factory methods
Dialog.show(.....);
> Create a new object
Dialog dialog = new Dialog();
dialog.show();
Copyright © 2009 Sun Microsystems, Inc. All rights reserved. 52
More about Dialogs
• Dialog type indicates an associated sound and icon
• Types:
> ALARM
> CONFIRMATION
> ERROR
> INFO
> WARNING
DialogDemo
54
Nesting Containers
• Container is a Component
• Container.addComponent(...) accept Components
• Each Container has its own layout
DialogDemo
nesting()
ComponentDemo
showTabbedPane()
57
Style
• Component attributes
> Colors -
– Normal: bgColor, fgColor
– Focus: bgSelectionColor, fgSelectionColor
> Font
> Transparency
> Image
> Margin, Padding
> Border
> Painter
ComponentMIDlet
• Store defaults in a .res file (a theme) showStyle()
Resource Editor
64
Animation
• Simple interface
> animate() - if returns 'true', paint will be called
> paint()
• De-activate
> form.deregisterAnimated(AnimatedComponent);
• Form menus
> setMenuTransitions(Transition tIn,
Transition tOut)
• Components in a container
> replace(Component current, Component next,
final Transition t)
> replaceAndWait(...)
DialogDemo
dialog3()
68
Mobile 3D Graphics (M3G, JSR 184)
• M3G class is a bridge to JSR 184
• Use renderM3G() to invoke your callback to
render 3D graphics
• See LWUIT’s own Transition3D for an example
73