My J2ME programming exercises (8) - canvas3

xiaoxiao2021-03-05  48

/ * * Canvas3let.java * * CREATED ON April 20, 2005, 3:55 pm * /

Import javax.microedition.midlet. *; import javax.microedition.lcdui. *;

/ ** * * @author Administrator * @version * / public class Canvas3let extends MIDlet implements CommandListener {private Display aDisplay; private Command okCommand; private Command exitCommand; private Command backCommand; private TextBox aTextBox; private Alert showAlert; private Image showImage; private Mycanvas Amycanvas; Public Canvas3let () {EXIXTCOMMAND = New Command ("Exit", Command.exit, 1); Okcommand = New Command ("Enter", Command.ok, 1); Try {ShowImage = Image.createImage ("/ SOHU.PNG ");} catch (exception e) {} showalert = new alert (" loading ... "," load ... ", showimage, alerttype.info; atextbox = new textbox (" KeyPress Test " "After pressing the entry button, you can enter the display interface, you can display the button", 25, Textfield.Any; atextbox.addcommand; atextbox.addcommand (okcommand); atExtBox.setcommandListener (this);} Public Void Sta rtApp () {aDisplay = Display.getDisplay (this); aDisplay.setCurrent (aTextBox);} public void pauseApp () {} public void destroyApp (boolean unconditional) {} public void commandAction (Command c, Displayable d) {if ( c == exitCommand) {destroyApp (false); notifyDestroyed ();} else if (c == okCommand) {aMyCanvas = new MyCanvas (); aDisplay.setCurrent (aMyCanvas);}} public class MyCanvas extends Canvas implements CommandListener {String Keyname = ""

Public mycanvas () {backcommand = new command ("Back", Command.exit, 1); addcommand (backcommand); setcommandlistener (this);} public void Paint (graphics g) {// Clear screen G.SetColor (0xfffffff) G.fillRect (0, 0, getWidth (), getHeight ()); // Set the font color and draw the name of the button G.SetColor (0); g.drawstring (KeyName, 100, 100, Graphics.Left | graphics .BOTTOM);} public void commandAction (Command c, Displayable d) {if (c == backCommand) {hideNotify (); //aDisplay.setCurrent(aTextBox);}} public void keyPressed (int keyCode) {keyName = getKeyName (Keycode); repaint ();} protected void hideNotify () {adisplay.setcurrent (showlert, attextbox);}}} The usage of KeyPress is mainly practiced by this program. In addition, there is Hidenotify () usage, but the usage of Shownotify () is not very clear.

HIDENOTIFY () is the implementation of this method immediately after the canvas is removed from the display.

Shonotify () is the system will call the method before the canvas appears before the display is displayed.

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

New Post(0)