J2ME Classes
- Displayable class
- Display class
- Command class
- Form class
- List class
- TestBox class
- TextField class
- Gauge class
- Datefield class
- Image class
- ImageItem class
- ChoiceGroup class
- Canvas class
- Gamecanvas class
Displayable class
A Displayable class is used with an object that can be placed or displayed on a screen. Commands, title or ticker in an MIDP application can be a Displayable object. the methods in displayable class are as follows.
void addCommand(Command cmd)
int getHeight()
Ticker getTicker()
int getWidth()
Display class
Diaplay class is used to manage the objects that can be displayed on the screen.The display.setCurrent() method is used to display a current object on the screen. A new display object can be created as follows.
Display display = Display.getDisplay(this);
Command class
The comand class is used to set command buttons on the display screen. By clicking on these command the applications will perform a pre-defined action. There are various types of command actions in the command class as follows
BACK
CANCEL
EXIT
HELP
OK
ITEM
SCREEN
STOP
These command types can be set as required. A new command class object can be created as follows
Commmand cmd = new Command(String label, int Commandtype, int priority);
Form class
Form class is used to create a user defined form in the Midlet. The form has several sub-classes which include gauge, textfield, datefield, customitem, stringitem, imageitem and choicegroup class. A new form object can be created as follows.
Form form = new Form(String label);
List class
The list class is used to create list of items that will allow users to select options from a given list of options. The list class works similar to the choicegroup class. A new list object can be created as follows.
List list = new List(String title, Choice.EXCLUSIVE|MULTIPLE);
TextBox class
The textbox class is used to create a text box in the MIDP application tha will allow the user to enter inputs. The syntax for creating a new TextBox object is as follows
TextBox textbox = new TextBox(String title, String text, int maxsize, int constraints);
TextField class
The textfiled class is used to create a new textfield in the MIDP application wherein the users can enter the inputs. The difference between textbox and textfield class is that textfield does not limit the amount of characters that can be entered in the textfield. A new textfield object can be created as follows.
TextField textfield = new TextField(String title, " ", 256, TextField.ANY);
Gauge class
The Gauge class is used to indicate a downloading bar or progress bar in an MIDP application. There are two types of gauges in J2ME viz; interactive and non-interactive. The interactive gauge continously shows the progress. A new gauge object can be created as follows.
Gauge bar = new Gauge(String title, boolean true|false, int maxpercentage, int minpercentage);
DateField class
The datefield class is used to display the current date and time in an MIDP application. A new datefield object can be created as follows.
DateField datefield = new DateField(String title, DateField.DATE|TIME|DATE_TIME);
Image class
The image class is used to create a new image that can be displayed in an MIDP application. The image class is used in conjunction with the imageitem class, so that the image can be appended in a form. A new image can be created as follows.
Image image = Image.createImage("/filename.png");
ImageItem class
The imageitem class is used to append an image that was created using the image class to a form. The syntax for creating a new imageitem is as follows
ImageItem imageitem = new ImageItem("image", image, ImageItem.LAYOUT_CENTER, "image");
ChoiceGroup class
The choicegroup class is used to create a list of choices in the MIDP application wherein the users can select multipe choice or a single choice. The syntax for creating a new choicegroup object is as follows.
ChoiceGroup choicegroup = new ChoiceGroup(String titile, Choice.EXCLUSIVE|MULTIPLE);
Canvas class
The canvas class is used to create graphical images and manipulate graphical objects in an MIDP application. The canvas class implements the abstract method public void paint(Graphics g). In addition to this, several other methods present in the canvas class are as follows.
protected void KeyPressed(int keycode)
protected void KeyReleased(int keycode)
protected void KeyRepeated(int keycode)
protected void PointerPressed(int x, int y)
protected void PointerReleased(int x, int y)
protected void PointerDragged(int x, int y)
GameCanvas class
The gamecanvas class is used to create game applications that can be executed on a mobile device. It has several methods that can be used for implementing a game application
A Displayable class is used with an object that can be placed or displayed on a screen. Commands, title or ticker in an MIDP application can be a Displayable object. the methods in displayable class are as follows.
void addCommand(Command cmd)
int getHeight()
Ticker getTicker()
int getWidth()
Display class
Diaplay class is used to manage the objects that can be displayed on the screen.The display.setCurrent() method is used to display a current object on the screen. A new display object can be created as follows.
Display display = Display.getDisplay(this);
Command class
The comand class is used to set command buttons on the display screen. By clicking on these command the applications will perform a pre-defined action. There are various types of command actions in the command class as follows
BACK
CANCEL
EXIT
HELP
OK
ITEM
SCREEN
STOP
These command types can be set as required. A new command class object can be created as follows
Commmand cmd = new Command(String label, int Commandtype, int priority);
Form class
Form class is used to create a user defined form in the Midlet. The form has several sub-classes which include gauge, textfield, datefield, customitem, stringitem, imageitem and choicegroup class. A new form object can be created as follows.
Form form = new Form(String label);
List class
The list class is used to create list of items that will allow users to select options from a given list of options. The list class works similar to the choicegroup class. A new list object can be created as follows.
List list = new List(String title, Choice.EXCLUSIVE|MULTIPLE);
TextBox class
The textbox class is used to create a text box in the MIDP application tha will allow the user to enter inputs. The syntax for creating a new TextBox object is as follows
TextBox textbox = new TextBox(String title, String text, int maxsize, int constraints);
TextField class
The textfiled class is used to create a new textfield in the MIDP application wherein the users can enter the inputs. The difference between textbox and textfield class is that textfield does not limit the amount of characters that can be entered in the textfield. A new textfield object can be created as follows.
TextField textfield = new TextField(String title, " ", 256, TextField.ANY);
Gauge class
The Gauge class is used to indicate a downloading bar or progress bar in an MIDP application. There are two types of gauges in J2ME viz; interactive and non-interactive. The interactive gauge continously shows the progress. A new gauge object can be created as follows.
Gauge bar = new Gauge(String title, boolean true|false, int maxpercentage, int minpercentage);
DateField class
The datefield class is used to display the current date and time in an MIDP application. A new datefield object can be created as follows.
DateField datefield = new DateField(String title, DateField.DATE|TIME|DATE_TIME);
Image class
The image class is used to create a new image that can be displayed in an MIDP application. The image class is used in conjunction with the imageitem class, so that the image can be appended in a form. A new image can be created as follows.
Image image = Image.createImage("/filename.png");
ImageItem class
The imageitem class is used to append an image that was created using the image class to a form. The syntax for creating a new imageitem is as follows
ImageItem imageitem = new ImageItem("image", image, ImageItem.LAYOUT_CENTER, "image");
ChoiceGroup class
The choicegroup class is used to create a list of choices in the MIDP application wherein the users can select multipe choice or a single choice. The syntax for creating a new choicegroup object is as follows.
ChoiceGroup choicegroup = new ChoiceGroup(String titile, Choice.EXCLUSIVE|MULTIPLE);
Canvas class
The canvas class is used to create graphical images and manipulate graphical objects in an MIDP application. The canvas class implements the abstract method public void paint(Graphics g). In addition to this, several other methods present in the canvas class are as follows.
protected void KeyPressed(int keycode)
protected void KeyReleased(int keycode)
protected void KeyRepeated(int keycode)
protected void PointerPressed(int x, int y)
protected void PointerReleased(int x, int y)
protected void PointerDragged(int x, int y)
GameCanvas class
The gamecanvas class is used to create game applications that can be executed on a mobile device. It has several methods that can be used for implementing a game application
J2ME program to display a text and take user-inputs.
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Sample extends MIDlet
{
private Display display;
private TextBox textbox;
public Sample()
{
display = Display.getDisplay(this);
textbox = new TextBox("hello", " ", 256, TextField.ANY);
}
public void startApp()
{
display.setCurrent(textbox);
}
public void pauseApp{ }
public void destroyApp(boolean unconditional)
{
notifyDestroyed();
}
}

1 comment:
great article
Post a Comment