站内搜索: 请输入搜索关键词

当前页面: 开发资料首页J2ME 专题J2ME编程实例---之数字键的测试

J2ME编程实例---之数字键的测试

摘要: J2ME编程实例---之数字键的测试
<td style="width:130px;height:130px;padding-bottom:10px;"> ad </td></tr> </table
  函数
  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.TOP|Graphics.LEFT);
  
    }
    protected void keyPressed(int keyCode) {
  
    aMessage = getKeyName(keyCode);
    aMessage = "数字"+aMessage+"已被按下";
    repaint();
  
    }
  
  }
  //

↑返回目录
前一篇: 如何搭建J2ME的开发环境之一二
后一篇: 如何使用“月蚀”进行J2ME开发