到 Google 资讯主页   
EasyJF首页   资料   源码   软件    论坛   网站    
   使用帮助    
    该信息为本站MyRSS系统缓存内容,部分图片及附件有可能无法正常使用.easyjf.comwww.javaresearch.org无关,不对该信息负责.通过http://www.javaresearch.org/article//showarticle.jsp?column=3&thread=1113访问该信息的原始内容.
页面功能  【加入收藏】 【推荐给朋友】 【字体:  】 【关闭】   
J2ME编程实例之数字键测试
作者:Zergling 来源:www.javaresearch.org  发布时间:2006-02-27 16:12:20.78


函数
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();
    
    }

}
//
刘洋
2001/7/23






 
相关文章
 
页面功能  【加入收藏】 【推荐给朋友】 【字体:  】 【关闭】   


EasyJF.com 2006 隐私政策 使用EasyJF前必读