We are embedded in the PC environment called Applet, and the program written must extend its own class from the Applet class.
The kjava program written for mobile information devices such as mobile phones is called MIDlet, and the program must expand its own class from the MIDlet class. A MIDLET process
The order is a typical structure:
Public class helloword extends midlet {helloword () {...}
Public void startapp () {......}
Public void pauseapp () {......}
Public void destroyApp (boolean unconditional) {...}}
When the program is started, startApp () is called by the system. (If the program is started when the program starts running, the program can also be opened again after being suspended.
move). PauseApp () is called when the program is temporarily stopped. When the program execution ends, DESTROYAPP () is called. We can
The actual situation is performed in each function.
There is no AWT or SWING in Motorola SDK, because their implementation will cost too much resources, Motorola SDK is just
There are also LCD-based comparisons based on some simple design user interfaces based on Javax.MicRoEdition.lcdui. Various SDK
Displable class (such as form), the currently displayed screen in the program must be an instance of a Displable, and the button can be placed in this instance.
Text editing box, radio box, etc. UI.
3. Example
Below is a simple example of running on a A6288 mobile phone with Kjava. The specific procedures are as follows:
Import java.io. *; import javax.microedition.lcdui. *; import javax.microedition.midlet. *;
Public class helloworld extends MIDlet imports commandlistener {
Private maincanvas mycanvas; private display mydisplay; private comman C1, C2, C3;
HelloWorld () {mycanvas = new maincanvas (); mycanvas.addcommand (c1 = new command ("first", command.screen, 1); mycanvas.addcommand (c2 = new command ("second", command.screen, 1 ))); mycanvas.addcommand (c3 = new command ("think", command.screen, 1)); mycanvas.setcommandlistener (this); mydisplay = display.getdisplay; mydisplay = display.getdisplay;}
Public void startapp () throws midletStateChangeException {mycanvas.setup ("first"); mydisplay.setcurrent (mycanvas);}
Public void pauseapp () {}
Public void destroyApp (boolean unconditional) {}
Public void CommandAction (Command C, Displayable D) {Mycanvas.Setup (c.getlabel ());}
Class Maincanvas Extends Canvas {String TS;
Maincanvas () {Super (); ts = new string ("first");} public void setup (string s) {ts = new string (s);}
Public void Paint (Graphics G) {g.setcolor (0xfffffff); G.FillRect (0, 0, getWidth (), getHeight ()); g.setcolor (0); g.drawstring ("current is the" TS GetWidth () / 2, 60, graphics.hcenter | graphics.top);}}}
After the program is run, different menu items can be displayed according to the different menu items selected.