Main class MIDlet:
Package com. lvke. wuwu;
Import javax. microedition. lcdui. display;
Import javax. microedition. MIDlet. MIDlet;
Import javax. microedition. MIDlet. midletstatechangeexception;
Public class pointexample extends MIDlet {
Display display;
Myclass canvas;
Public pointexample (){
Display = display. getdisplay (this );
Canvas = new myclass (this );
}
Protected void Startapp () throws midletstatechangeexception {
Display. setcurrent (canvas );
}
Protected void destroyapp (Boolean B) throws midletstatechangeexception {
}
Protected void pauseapp (){
}
Public void midletexit (){
Try {
This. destroyapp (false );
} Catch (midletstatechangeexception e ){
E. printstacktrace ();
}
This. policydestroyed ();
}
}
Function implementation class:
Package com. lvke. wuwu;
Import javax. microedition. lcdui. Canvas;
Import javax. microedition. lcdui. Command;
Import javax. microedition. lcdui. commandlistener;
Import javax. microedition. lcdui. displayable;
Import javax. microedition. lcdui. graphics;
Public class myclass extends canvas implements commandlistener {
Private command exit;
Private command arase;
Private Boolean araseflag = false;
Private Boolean isfirstpaint;
Private int SX = 0, Sy = 0, Cx = 0, Cy = 0;
Private pointexample point;
Public myclass (pointexample point ){
This. Point = point;
Exit = new command ("exit", command. Exit, 1 );
Arase = new command ("arase", command. screen, 1 );
This. addcommand (exit );
This. addcommand (arase );
This. setcommandlistener (this );
Isfirstpaint = true;
}
Public void commandaction (command C, displayable d ){
If (C = exit ){
Point. midletexit ();
} Else if (C = arase ){
Araseflag = true;
Repaint ();
}
}
Protected void paint (Graphics g ){
If (araseflag | isfirstpaint ){
G. setcolor (255,255,255 );
G. fillrect (0, 0, this. getwidth (), this. getheight ());
Araseflag = isfirstpaint = false;
SX = 0; Sy = 0; Cx = 0; Cy = 0;
Return;
}
G. setcolor (255, 0, 0 );
System. out. println ("SX =" + SX + ": Sy =" + Sy + ": Cx =" + cx + ": Cy =" + cy );
G. drawline (sx, Sy, CX, CY );
SX = Cx;
Sy = Cy;
}
// Trigger an event when you press the mouse or click the screen
Protected void pointerpressed (int x, int y ){
SX = X;
Sy = y;
}
// This event is triggered when you drag the mouse or draw a screen.
Protected void pointerdragged (int x, int y ){
Cx = X;
Cy = y;
Repaint ();
}
}
: