Wednesday, May 4, 2011
What is Java 2 Micro Edition?
Java is known primarily as a server-side programming environment, centered around the technologies that make up the Java 2 Enterprise Edition (J2EE), such as Enterprise JavaBeans (EJBs), servlets, and JavaServer pages (JSPs). Early adopters of Java, however, will recall that it was originally promoted as a client-side application environment. In fact, Java was originally designed as a programming language for consumer appliances. Now Java is returning to its roots with Java 2 Micro Edition, or J2ME for short.
The Java 2 Platform
What we commonly refer to as "Java" is more formally known as the Java 2 Platform. The Java 2 Platform is split into three editions: Java 2 Standard Edition (J2SE), Java 2 Enterprise Edition (J2EE), and Java 2 Micro Edition (J2ME). Each edition of the platform provides a complete environment for running Java-based applications, including the Java virtual machine (VM) and runtime classes.
Java 2 Micro Edition
In J2ME, the Java runtime environment is adapted for constrained devices - devices that have limitations on what they can do when compared to standard desktop or server computers. For low-end devices, the constraints are fairly obvious: extremely limited memory, small screen sizes, alternative input methods, and slow processors. High-end devices have few, if any, of these constraints, but they can still benefit from the optimized environments and new programming interfaces that J2ME defines.
Monday, May 2, 2011
J2ME Thread Processing Example
In the given example, you will learn about the thread and how thread works in
J2ME application. An application can run multiple activities simultaneously
using thread. Here we have defined different states of thread...
The states of Thread is:
- running:- Executing code.
- ready:- Ready to execute code.
- suspended:- Waiting on an external event.
- terminated:- Finished executing code.
In the output First of all process() thread will be executed then start()
thread and then run() thread will be executed.
The Application is as follows:
Source Code of ThreadProcessing.java
|
Output:
J2ME Thread Processing Example
In the given example, you will learn about the thread and how thread works in
J2ME application. An application can run multiple activities simultaneously
using thread. Here we have defined different states of thread...
The states of Thread is:
- running:- Executing code.
- ready:- Ready to execute code.
- suspended:- Waiting on an external event.
- terminated:- Finished executing code.
In the output First of all process() thread will be executed then start()
thread and then run() thread will be executed.
The Application is as follows:
Source Code of ThreadProcessing.java
|
Output:
J2ME Ticker Example
This is the simple Ticker example which is used to auto scroll the data on
the top of the form. It continuously scroll the data. The javax.microedition.lcdui.Ticker
has only one constructor that is:
Ticker(String str):- This is used to Constructs a new Ticker object,
given its initial contents string.
And it has two methods:
getString():- This is the String type methods which Gets the string
currently being scrolled by the ticker.
setString(String str):- This is the void type, it Sets the string to
be displayed by this ticker.
The Application looked as below:
Source Code of TickerExample.java
|
Friday, April 29, 2011
Creating Multiple Type List
This example is shows how to create the list which has multiple type choice
option. In this example user can make selection in name list and after selection
application will display message according to the selection. Like..........
Sandeep: selected Kumar: selected Suman: not selected |
The MULTIPLE keyword is used to create the multiple type list as
follows:
list = new List("Multiple Option", List.MULTIPLE); |
The application look like as follows:
Source Code Of MultipleList.java
|
Output:
Creating Menu Using Canvas Class
This example shows how to create the menu and call the canvas class to show
the toggle message. The Toggle message will appear when user perform some action
like click on a button ("Show"). In this example we have used the
following method:
- setColor()
- fillRect()
- getWidth()
- getHeight()
- getFont()
- fontHeight()
- fontWidth()
- setFont()
- drawString()
- repaint()
The repaint() method is used to appear the string on Canvas form.
The application look like as follows:
Source Code For CanvasMenu.java
|
J2ME Canvas Example
A J2ME Game Canvas Example
This example illustrates how to create a game using GameCanvas class.
In this example we are extending GameCanvas class to draw the circle and
rotate the circle continuously. The GameCanvas class has following
methods:
- flushGraphics():- This is the void type method, it flushes to
display on the off-screen buffer. - flushGraphics(int x, int y, int width, int height):- This is the
void type method, it flushes to display of specified region on the
off-screen buffer. - getGraphics():- This is used to get the graphics objects.
- getKeyStates():- This is the integer type variable, it is used to
find the states of the key. - paint(Graphics g):- This is also the void type method, it is used
to paint the canvas.
Other commands, input event, etc methods inherited from Canvas class.
The Canvas class has following methods:
- getGameAction(int keyCode)
- getHeight()
- getKeyCode(int gameAction)
- getKeyName(int keyCode)
- getWidth()
- hasPointerEvents()
- hasPointerMotionEvents()
- hasRepeatEvents()
- hideNotify()
- isDoubleBuffered()
- keyPressed(int keyCode)
- keyReleased(int keyCode)
- keyRepeated(int keyCode)
- paint(Graphics g)
- pointerDragged(int x, int y)
- pointerPressed(int x, int y)
- pointerReleased(int x, int y)
- repaint()
- repaint(int x, int y, int width, int height)
- serviceRepaints()
- showNotify()
Source Code of CanvasGame.java
|
List in J2ME
Exclusive List MIDlet Example
This example illustrates how to create a Exclusive List. The Exclusive List
is used to select only one list element at a time. The EXCLUSIVE Field
inherited from interface javax.microedition.lcdui.Choice. There are three
choices in this interface, that are:
- EXCLUSIVE
- IMPLICIT
- MULTIPLE
The one line code of Exclusive Choice is as follows:
list = new List("Movies", Choice.EXCLUSIVE) |
In the next example, you will see how to use implicit choice list
The EXCLUSIVE List Look like as follows:
Source Code Of ExclusiveChoiceList.java
|
Thursday, April 28, 2011
J2ME List Image
List Image MIDlet Example
This example illustrates how to create list with image symbol. In this
example we are trying to create list using of List class. The List class define
in two type of constructors, that is:
- List(String title, int listType)
- List(String title, int listType, String[] stringElements, Image[]
imageElements)
The List class has following Methods:
- append(String stringPart, Image imagePart):- This method is the
integer type, which is used to append an element to the choice. - delete(int elementNum):- This is the void type which deletes the
element. - getImage(int elementNum):- This is the Image type which gets the
image. - getSelectedFlags(boolean[] selectedArray_return):- This is integer
type method which has the state of a Choice and returns the state of all
elements in the boolean array. - getSelectedIndex():- This is the integer type which returns the
index number of an element in the Choice that is selected. - getString(int elementNum):- This method is used to get the String
of the element. - insert(int elementNum, String stringPart, Image imagePart):- This
is void type it inserts an element into the Choice just prior to the element
specified. - isSelected(int elementNum):- It gets the boolean value indicating
whether element is selected or not. - set(int elementNum, String stringPart, Image imagePart):- It sets
the element to the specified element, replacing the previous contents of the
element. - setSelectedFlags(boolean[] selectedArray)
- setSelectedIndex(int elementNum, boolean selected)
- size()
The SELECT_COMMAND is used to recognized whether user select from list
or not.
Source Code of ListImage.java
|
J2ME Contact List
This Example goes to create a Phone Book MIDlet
This example illustrates how to create your phone book. In this example
we are taking three SCREEN button ("Next", "New",
"Exit") and taking two TextBox ("name",
"number"). In the name field user enters name and in number field
user enters phone number. When user enters name and click on Next button then
number text box will open, now user enters phone number. In case user
select "Exit" or "New" the name and number
get prints on the console.
When
program will run initially, startApp() method will be called. And both
"Enter Name" text box and the "Next" button will be
displayed. After that if user clicks on next button the commandAction() method
will be called that will check, if label is equal to "Next" then number TextBox
will appear on the screen that can be used to enter the phone number of
user.
The application display as below:
Source code of PhoneBookExample.java
|