GUI in MIDP

Click here to load reader

download GUI in MIDP

of 37

Transcript of GUI in MIDP

GUI Design in MIDPFENIL GANDHI ROLL NO. 105 MBA Tech I.T.

Introductiony Mobile Information Device Profile (MIDP) is a specification published

for the use of Java on embedded devices such as mobile phones and PDAs. y When combined with the Connected Limited Device Configuration (CLDC), MIDP provides a standard Java runtime environment for today's most popular mobile information devices, such as cell phones and mainstream personal digital assistants (PDAs).y AWT and SWING are not supported in MIDP, since y Limited resources in MIDP y No mouse y No Window

2

Display0..1 0..n

Displayable

Command

Canvas

Screen

Graphic

Alert

List

TextBox

Form0..n

Item

TextField3

DateField

Gauge

ChoiceGroup

StringItem

ImageItem

y All MIDP GUI classes are in the lcdui

package import javax.microedition.lcdui.*; y Only one Displayable can be displayed, Screen or Canvas y Four kinds of Screeny Predefined Components List, Alert, and TextBox y Container Form

4

Listy A list is a screen of choices y Three types of lists y Exclusive Choice List enables the user to select one and only one element y Multiple Choice List enables the user to select zero or more elements y Implicit List enables the user to select one element and execute an action on it

5

y An example ListTest.javay Exclusive choice and multiple choice

y Add Commands to catch the conform events

List l = new List(List Test, Choice.EXCLUSIVE); l.append (Item 1, null);

6

Alertsy An alert is a screen that gives users error messages or status

information y AlertTypey Alarm, Confirmation, Error, Info, Warning

y setTimeout(t) set the time for which the Alert is to be

shown y An example AlertTest.java

7

TextBoxy Text boxes are editable screens that can display one or more

lines of text y Constructor TextBox(title, text, maxSize, constraints) y Constraintsy ANY, EMAIL_ADDR, NUMERIC, PASSWORD,

PHONENUMBER, URL, CONSTRAINT_MASK

8

y An example TextBoxTest.java

new TextBox("TextBox ", "initial text", 256, TextField.ANY);

9

Formsy A form is a screen that can contain an arbitrary mixture of

items: images, text fields, gauges, choice groups, and so on

10

Form Itemsy Forms contain one or more items, each of which can have a

label y Itemsy StringItem, ImageItem, TextField, DateField, Guage,

ChoiceGroupy getLabel(), setLabel(label) defined in class Item

11

y StringItems are similar to labels. y They have name or label and display string items. y StringItem StringItemTest.javay getText(), setText()

12

y ImageItem

Provides layout control when Image objects are added to a Form or to an Alert ImageItemTest.javay Image Object

Image.createImage("/icons/Icon.png"); y ImageItem ImageItem(label string, image object, layout, atlText); y Item layout

13

What's an Exception and Why Do I Care?y An exception is an event that occurs during the execution of

a program that disrupts the normal flow of instructionsy Throwing an exception y Exception handler

14

Exception Handling in Javay What's an Exception and Why Do I Care? y Your First Encounter with Java Exceptions y Java's Catch or Specify Requirement y Dealing with Exceptions y Throwing Exceptions

15

Catching and Handling Exceptionsy Specifying the exceptions thrown by a methody the try block y the catch block(s) y the finally blocktry { ... } catch (SomeThrowable variable) { Java statements } catch ( . . . ) { ... } finally { }16

y ChoiceGroup

A group of selectable elements intended to be placed within a Form ChoiceGroupTest.javay ChoiceGroup

new ChoiceGroup("ChoiceGroupTest", Choice.EXCLUSIVE) y Only EXCLUSIVE and MULTIPLE are allowed ChoiceGroupTest2.java new ChoiceGroup("ChoiceGroupTest", Choice.MULTIPLE)

17

y TextField y Similar to previous TextBox y Gauge a bar graph display of a value intended for use in

a form GaugeTest.javay Constructor

Gauge(label, interactive, maxValue, initValue) y Methods setValue() getValue(value)18

y DateField an editable component for presenting date and

time information that may be placed into a Form DateFieldTest.javay Constructor

DateField(label, mode, timeZone)y Mode: DateField.DATE, DateField.TIME, and

DateField.DATE_TIME

19

20

y Tiker - a piece of text that runs continuously across the

display TickerTest.javay Ticker can be add to any Screen except Canvas

f.setTicker(ticker) -- f is a form f.getTicker().setString(new string); y Methody setString(string), getString()

21

Canvasy The Canvas class is a base class for writing applications that

need to handle low-level events and to issue graphics calls for drawing to the display y The Canvas extends from Displayable y Only one Displayable can be displayed, Screen or Canvas

22

Event Delivery in Canvasy y y y y y y y y y

paint(Graphics g) showNotify() hideNotify() keyPressed() keyRepeated() keyReleased() pointerPressed() pointerDragged() pointerReleased() the CommandListener's commandAction() method

23

Other Methods of Canvasy getHeight(), getWidth() y getGameAction(keyCode) y getKeyCode(gameAction) y repaint() y hasPointerEvents() y hasPointerMotionEvents() y hasRepeatedEvents() y isDoubleBuffered()

24

Graphicsy For drawing graphics in Canvas y Setting methodsy setColor, setFont(), setGrayScale(), setStrokeStyle(), translate()

y Drawing methodsy drawChar(), drawChars(), drawString(), drawSubString(),

drawLine(), drawRect(), drawArc(), drawRoundRect(), fillArc(), fillRect(), fillRoundRect(), drawImage()

25

Using Canvasy Define your own Canvas class by extending from class

Canvasy Override paint() for drawing graphics y Override event handling methods to handle low level events

y Use your own Canvas as previous Displayable classes y Instantiate your own Canvas object and set it to the display

26

Checking Size of Canvasy yy y

MethodsgetHeight(), getWidth()

An exampleSizeCanvas.java SizeMIDlet.java

y yy

Two class in a MIDlet suite, but only one MIDlet drawString(string, x, y, anchor)Anchor =(LEFT, HCENTER, RIGHT) | ((TOP, BASELINE, BOTTOM)

27

Coordination Systems of Canvasy Methodsy translate(x, y) translate origin to (x, y) y getTranslateX(), getTranslateY()

y An Exampley OrigTransCanvas.java y OrigTransMIDlet.java

int step = width/5; for(int i=1; i