Solve the problem that PAINT () and user input response will be made using Thread.
Public class mycanvas expert {int R = 0; public mycanvas () {thread t = new thread (this); T.Start ();} public void run () {while (true) {R ; if (r > 10) R = 0; repaint ();}} public void Paint (GRAPHICS G) {CLEAR (G); PaintaniMation (G, 100, 10, R);} protected void keypressed (int keycode) {switch (getGameAction) Keycode)) {CASE CANVAS.UP: Y = Y-2; Break; ......}}}}
J2ME has taken the stop () method (J2SE no longer promotes it), we use the logo (FLAG) to solve the problem of the end of the thread Boolean Conti = False; ... if (cmd.equals)) {Conti = false; RemoveCommand (STOP); addcommand (start);} else if (cmd.equals)) {remotecommand (start); addcommand; strai = true; thread t = new three (this); T.Start ();} ... public void run () {while (conti) {R ; if (r> 10) r = 0; repaint ();}}
Time control different machine processing speed, in order to keep the game, the screen consistency, solve the time control process ... int RATE = 50 (50 millisecond = 1/20 seconds to redraw once) public void Run () {long S1 = 0; long s2 = 0; long () {s1 = systen.currenttimemillis (); repaint (); service (); s2 = s2-s1; system. OUT.RPINTLN (DIFF); if (Diff