扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class KeyCodes extends MIDlet { private Display display; private KeyCodeCanvas canvas; public KeyCodes() { display = Display.getDisplay(this); canvas = new KeyCodeCanvas(this); } protected void startApp() { display.setCurrent(canvas); } 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's go!"; private KeyCodes midlet; public KeyCodeCanvas(KeyCodes midlet) { this.midlet = midlet; cmExit = new Command("Exit", Command.EXIT, 1); addCommand(cmExit); setCommandListener(this); } protected void paint(Graphics g) { System.out.println("I am invoked!"); g.setColor(0, 255, 0); g.fillRect(0, 0, getWidth(), getHeight()); if (keyText != null) { g.setColor(0, 0, 0); g.drawString(keyText, getWidth() / 2, getHeight() / 2, Graphics.TOP | Graphics.HCENTER); } } public void showNotify() { repaint(); try { Thread.sleep(2000); } catch(InterruptedException e) { } } public void commandAction(Command c, Displayable d) { if (c == cmExit) midlet.exitMIDlet(); } protected void keyPressed(int keyCode) { keyText = getKeyName(keyCode); repaint(); try { Thread.sleep(2000); } catch(InterruptedException e) { } } } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者