600 likes | 864 Views
PROGRAMMING WITH J2ME. Presenter: Tran Duc Minh Email: minhtd@gmail.com. CONTENT. Introduction to J2ME and MIDP Setting environment for J2ME Standard GUI Low level GUI. 1. Introduction to J2ME and MIDP. Configuration Connected Device Configuration (CDC)
E N D
PROGRAMMING WITH J2ME Presenter: Tran Duc Minh Email: minhtd@gmail.com
CONTENT Introduction to J2ME and MIDP Setting environment for J2ME Standard GUI Low level GUI
1. Introduction to J2ME and MIDP Configuration Connected Device Configuration (CDC) Connected, Limited Device Configuration (CLDC)
1. Introduction to J2ME and MIDP Profiles MIDP MIDlets The Application Manager
Configuration A J2ME configuration defines a Java platform for a range of devices Each configuration encompasses the features available in the Java language as well as the core libraries
Connected Device Configuration (CDC) 512 kilobytes (minimum) memory for running Java programs 256 kilobytes (minimum) for run time memory allocation Network connectivity, possibly persistent, and high-bandwidth
Connected, Limited Device Configuration (CLDC) 128 KB of memory for running Java programs 32 KB of memory for run time memory allocation A limited user interface Runs on battery power Wireless network connection, low bandwidth
Profiles A J2ME profile is an extension of a configuration It defines the libraries available to a developer writing applications for a specific device type
MIDP The MIDP extends the CLDC MIDP defines APIs for UI components, input and event handling, persistent storage, and networking and timers… MIDP offers a high-level and low-level API
MIDlets A MIDlet is a Java application that is built on top of the CLDC and MIDP A MIDlet suite consists of one or more MIDlets packaged together as a JAR
The Application Manager The software on the mobile device that is responsible for installing, running, and removing MIDlets
2. Setting Environments Setting on Eclipse IDE Setting on Ktoolbar (See the attach demo)
3. Standard GUI Display, Displayable and Screen objects Form and Item List, Textbox, Alert, Ticker
Display, Displayable and Screen objects A MIDlet has one instance of a Display object. This object is used to obtain information about the current display
Display, Displayable and Screen objects A Displayable object is a component that is visible on a device. For example: Forms, TextBoxes, ChoiceGroups, etc. A Screen object is not something that is visible on the device Screen is subclassed by high-level components
Form and Item DateField Gauge StringItem TextField ChoiceGroup Image and ImageItem
DateField The DateField component provides a means to visually manipulate a Date object Construtor: DateField(String label, int mode) DateField(String label, int mode, TimeZone timeZone)
DateField The DateField has mode: DateField.DATE_TIME DateField.DATE_TIME DateField.DATE
Gauge A Gauge component displays a progress-meter style interface There are two types of Gauge: interactive and non-interactive Construtor: Gauge(String label, boolean interactive, int maxValue, int initialValue)
StringItem A StringItem component is used to display a label or string Construtor: StringItem(String label, String text)
TextField A Textfield is analogous to any typical text entry field Constructor: TextField(String label, String text, int maxSize, int constraints)
TextField TextField has following modes: ANY EMAILADDR NUMERIC PHONENUMBER URL PASSWORD
ChoiceGroup ChoiceGroup components allow a user to select from a predefined list of entries There are two ChoiceGroup mode: multi-selection(checkbox) and exclusive-selection(radio button) Constructor: (See the j2me api reference)
Image and ImageItem Image is used to create an image object and holds information MIDP offers two types of images: immutable and mutable
4.Low level GUI Canvas Graphics
Canvas The coordinate system Keycodes Game actions
Canvas The Canvas class provides the backdrop for creating a custom (or low-level) user interface Canvas provides a large number of methods to handle events and draw images and text onto the device display
The coordinate system Following methods determine the width and height of the canvas : int getWidth() int getHeight () The software on an MIDP device will always return the maximum drawing area available for a given device
The coordinate system The Canvas class method paint() lets you draw shapes, display images, write text… protected void paint(Graphics g) { // Set background color to white g.setColor(255, 255, 255); // Fill the entire canvas g.fillRect(0, 0, getWidth(), getHeight()); }
The coordinate system class TestCanvas extends Canvas implements CommandListener { private Command cmdExit; ... display = Display.getDisplay(this); cmdExit = new Command("Exit", Command.EXIT, 1); addCommand(cmdExit); setCommandListener(this); ... protected void paint(Graphics g) { // Draw onto the canvas ... } public void commandAction(Command c, Displayable d) { if (c == cmdExit) ... } }
Keycodes In addition to soft-keys for processing commands, a Canvas object has access to 12 keycodes The codes that are guaranteed to be available on any MIDP device
Keycodes KEY_NUM0, KEY_NUM1 KEY_NUM2, KEY_NUM3 KEY_NUM4, KEY_NUM5 KEY_NUM6, KEY_NUM7 KEY_NUM8, KEY_NUM9 KEY_STAR, KEY_POUND
Keycodes void keyPressed(int keyCode) void keyReleased(int keyCode) void keyRepeated(int keyCode) boolean hasRepeatEvents() String getKeyName(int keyCode)
Keycodes void keyPressed(int keyCode) void keyReleased(int keyCode) void keyRepeated(int keyCode) boolean hasRepeatEvents() String getKeyName(int keyCode)
Graphics Color support Stroke style Drawing shapes Working with fonts Anchor points Drawing text Drawing images Additional Graphics methods
Color support boolean isColor() int numColors() void setColor(int RGB) void setColor(int red, int green, int blue) int getColor() int int getRedComponent() int getGreenComponent() int getBlueComponent()
Stroke style int getStrokeStyle() void setStrokeStyle(int style) The two stroke style constants are: DOTTED SOLID
Draw Arc void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
Draw Rectangle void drawRect(int x, int y, int width, int height) void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) void fillRect(int x, int y, int width, int height) void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
Font Font getFont(int face, int style, int size) Font getFont(int fontSpecifier) Font getDefaultFont() Example: Font font = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD | Font.STYLE_ITALIC, Font.SIZE_MEDIUM); Font font = Font.getFont(Font.FONT_INPUT_TEXT);