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)
An Image/Link below is provided (as is) to download presentation
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.Content is provided to you AS IS for your information and personal use only.Download presentation by click this link.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.During download, if you can't get a presentation, the file might be deleted by the publisher.
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
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)
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)
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
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);