程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> JAVA編程入門知識 >> J2ME編程實例---之數字鍵的測試

J2ME編程實例---之數字鍵的測試

編輯:JAVA編程入門知識
  函數
  protected void keyPressed(int keyCode) {
  }
  讓我們能夠使用手機數字鍵
  下面是我編寫的一個實例,由兩個文件組成:
  
  //liuy002.Java
  package example.liuy.liuy002;
  
  import javax.microedition.lcdui.Display;
  import javax.microedition.lcdui.Form;
  import javax.microedition.midlet.MIDlet;
  import javax.microedition.midlet.MIDletStateChangeException;
  
  public class liuy002 extends MIDlet {
  
  /**
   * @see MIDlet#startApp()
   */
  protected void startApp() throws MIDletStateChangeException {
  Display d = Display.getDisplay(this);
  keytest f = new keytest();
  d.setCurrent(f);
  }
  
  /**
   * @see MIDlet#pauseApp()
   */
  protected void pauseApp() {
  }
  
  /**
   * @see MIDlet#destroyApp(boolean)
   */
  protected void destroyApp(boolean flag) throws MIDletStateChangeException {
  }
  }
  
  //keytest.java
  package example.liuy.liuy002;
  
  import javax.microedition.lcdui.Canvas;
  import javax.microedition.lcdui.Graphics;
  
  public class keytest extends Canvas {
  
  /**
   * ConstrUCtor for keytest
   */
  String aMessage = "[請按鍵]";
  
  
  protected keytest() {
  super();
  }
  
  /**
   * @see Canvas#paint(Graphics)
   */
  protected void paint(Graphics g) {
  
  g.drawString(aMessage,10,10,Graphics.TOPGraphics.LEFT);
  
  }
  protected void keyPressed(int keyCode) {
  
  aMessage = getKeyName(keyCode);
  aMessage = "數字"+aMessage+"已被按下";
  repaint();
  
  }
  
  }
  //
 
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved