本文主要闡述的問題是
通過參考Java doc我們可以知道在J
showNotify()
hideNotify()
keyPressed()
keyRepeated()
keyReleased()
pointerPressed()
pointerDragged()
pointerReleased()
paint()
the CommandListener
我們針對上述串行化的理解不防做一下這樣的假設
import javax
import javax
public class KeyCodes extends MIDlet
{
private Display display;
private KeyCodeCanvas canvas;
public KeyCodes()
{
display = Display
canvas = new KeyCodeCanvas(this);
}
protected void startApp()
{
display
}
protected void pauseApp()
{
}
protected void destroyApp(boolean unconditional)
{
}
public void exitMIDlet()
{
destroyApp(true);
notifyDestroyed();
}
}
class KeyCodeCanvas extends Canvas implements CommandListener
{
private Command cmExit;
private String keyText = "hello let
private KeyCodes midlet;
public KeyCodeCanvas(KeyCodes midlet)
{
this
cmExit = new Command("Exit"
addCommand(cmExit);
setCommandListener(this);
}
protected void paint(Graphics g)
{
System
g
g
if (keyText != null)
{
g
g
| Graphics
}
}
public void showNotify()
{
repaint();
try
{
Thread
}
catch(InterruptedException e)
{
}
}
public void commandAction(Command c
{
if (c == cmExit)
midlet
}
protected void keyPressed(int keyCode)
{
keyText = getKeyName(keyCode);
repaint();
try
{
Thread
}
catch(InterruptedException e)
{
}
}
}
編譯
在Canvas類的java doc中有一個備注說明了一些值得關注的問題
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20191.html