The
to distinguish J2ME programs from J2SE programs is based on the restricted environment in which J2ME runs. The main limiting condition for most J2ME systems is the size of the memory needed to store and run the program. For example, many MIDP devices limit the size of the application to 50K, which is far less than the megabytes in the server-side J2SE operating environment. In practical applications, programs can easily go beyond these limits. In this article you will learn some techniques to reduce the size of your program and practice these techniques in the following examples. This example MIDlet only displays a text box and sounds when its contents change.
Package com.j2medeveloper.techtips
Import javax.microedition.lcdui.*;
public class Beforesizeoptimization extends
Basicmidlet {
public static final Command exitcommand =
New Command ("Exit",
Command.exit, 1);
Public beforesizeoptimization () {
}
protected void Initmidlet () {
Getdisplay (). Setcurrent (New MainForm ( ) );
}
public class MainForm extends form {
Public mainform () {
Super ("MainForm");
AddCommand (Exitcomman D);
Append (TEXTF);
Setcommandlistener (New Commandlistener () {
public void commandaction (Command c,
displayable d) {
if (c = = Exitcommand) {
Exitmidlet ();
}
}
}
);
Setitemstatelistener (
New Itemstatelistener () {
public void itemstatechanged (
Item Item) {
if (item = = TEXTF) {
AlertType.INFO.playSound (
Getdisplay ());
}
}
}
);
}
Private TextField TEXTF =
New TextField ("Type anything", NULL,
0);
}
}