Canvas and its supported button event test

xiaoxiao2021-03-06  40

Click the simulator's SELECT button, then adjust it up and down, you can choose to start painting a three-dimensional button. Add the SELECT button, the upper and lower left and down, you can control the button's movement. IMPORT JAVAX.MICROED.LCDUI.CANVAS; Import Javax .microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Graphics; import javax.microedition.lcdui.Ticker; / * * Created on 2005- 1-29 * * Todo to change the Template for this generated file go to * window - preferences - java - code style - code templates * /

/ ** * @author jeremy chow * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates * / public class FullCanvasTest extends Canvas implements CommandListener {protected boolean pressed, drew; INT x = 50; int y = 50; int W = 1; int h = 1; intlene = 5; / ** * * / public fulliStest () {// super (); // Todo auto-generated constructor stub // setTitle (); PRESSED = false; Drew = false; settitle ("full screen test"); setticker (New Ticker); Addcommand (New Command ("full screen", command.screen, 1 ))); Addcommand (New Command ("Normal", Command.screen, 1); setcommandListener (this);}

/ * (Non-Javadoc) * @see javax.microedition.lcdui.Displayable # paint (javax.microedition.lcdui.Graphics) * / protected void paint (Graphics g) {// TODO Auto-generated method stub g.setColor ( 200, 200, 200); G.FillRect (0, 0, getWidth (), getHeight ()); setFullscreenmode (TRUE); PaintButton (G, X, Y, W, H, PRESSED); Paintcross (g, x w, y H, length);

Public Void PaintButton (Graphics G, INT X, INT Y, INT W, INT H, Boolean P) {if (! P) {G.SetColor (255, 255, 255); G.FillRect (x-1, y-1, w , H); G.SetColor (125, 125, 125); g.fillRect (x, y, w, h);} else {G.SetColor (255, 255, 255); g.fillRect (x, y, w, h) G.SetColor (125, 125, 125); G. FillRect (x-1, y-1, w, h);

}} PUBLIC VOID PAINTCROSS (GRAPHICS G, INT X, INT Y, INT LENGTH) {G.SetColor (255, 0); g.drawline (X-Length, Y, X Length, Y); g.drawline (x, y-length, x, y length);} / * (non-javadoc) * @see javax.microedition.lcdui.commandlistener # CommandAction (javax.microedition.lcdui.command, javax.microedition.lcdui.displayable * / Public void CommandAction (Command C, Displayable S) {// Todo Auto-generated method stub string cmd = c.getlabel (); if (cmd.equals)) {setfullscreenmode (true);} Else IF ("Normal")) {setFullScreenmode (false);}} protected (int W, int h) {system.out.println ("Change the width after changing: w); system. Out.println ("The height after changing:" h);} protected void hidenotify () {system.out.println ("screen is smoked");} protected void shownotify ()} protected void shownotify () Screen is displayed on the screen "); Protected void keypressed (int keycode) {system.out.println ("Press the key value:" getGameAction (Keycode)); switch (getGameAction (keycode)) {copy canvas.up: if (! Drew) y = Y - 2; Else H = H - 2; Break; Case Canvas.down: if (! Drew) y = y 2; Else H = H 2; Break; Case Canvas.Left: if (! Drew) x = X - 2; Else W = W - 2; Break; Case Canvas.right: if (! Drew) x = x 2; Else W = W 2; Break;

Case canvas.fire: pressed = true; break; default: Break;} // PRESSED = true; repaint ();} protected (} protected) {system.out.println ("released key value: getGameAction (keycode)); switch (getGameAction (keycode)) {case Canvas.FIRE: pressed = false; drew = drew; break; default:! break;} repaint ();}} import javax.microedition.lcdui.Display; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; / * * Created on 2005-1-29 * * TODO to change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates * // ** * @author jeremy chow * * TODO to change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates * / public class CanvasTestMIDlet extends MIDlet {protected Display display ; / ** * * / public canvastestMIDlet () {// super (); // Todo auto-generated constructor stub display = display.getdisplay;}

/ * (Non-Javadoc) * @see javax.microedition.midlet.MIDlet # startApp () * / protected void startApp () throws MIDletStateChangeException {// TODO Auto-generated method stub FullCanvasTest fc = new FullCanvasTest (); display.setCurrent (fc);

/ * (non-javadoc) * @see javax.microedition.midlet.midlet # Pauseapp () * / protected void Pauseapp () {// Todo auto-generated method stub

}

/ * (Non-Javadoc) * @see javax.microedition.midlet.MIDlet # destroyApp (boolean) * / protected void destroyApp (boolean arg0) throws MIDletStateChangeException {// TODO Auto-generated method stub}

}

转载请注明原文地址:https://www.9cbs.com/read-62808.html

New Post(0)