欢迎光临
我们一直在努力

我的J2ME编程练习(8)——Canvas3-JSP教程,Java基础

建站超值云服务器,限时71元/月

 

/*
 * canvas3let.java
 *
 * created on 2005年4月20日, 下午3:55
 */

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
 *
 * @author  administrator
 * @version
 */
public class canvas3let extends midlet implements commandlistener{
    private display adisplay;
   
    private command okcommand;
    private command exitcommand;
    private command backcommand;
   
    private textbox atextbox;
   
    private alert showalert;
   
    private image showimage;
   
    private mycanvas amycanvas;
   
    public canvas3let(){
        exitcommand=new command(“退出”,command.exit,1);
        okcommand=new command(“进入”,command.ok,1);
        try{
            showimage=image.createimage(“/sohu.png”);
        }
        catch(exception e){}
       
        showalert=new alert(“loading…”,”载入中……”,showimage,alerttype.info);
       
       
        atextbox=new textbox(“keypress test”,
                “按下进入键后,即可进入显示界面,可以显示所按按键”,
                25,textfield.any);
       
        atextbox.addcommand(exitcommand);
        atextbox.addcommand(okcommand);
        atextbox.setcommandlistener(this);
       
       
       
    }
    public void startapp() {
        adisplay=display.getdisplay(this);
        adisplay.setcurrent(atextbox);
    }
   
    public void pauseapp() {
    }
   
    public void destroyapp(boolean unconditional) {
    }
   
    public void commandaction(command c , displayable d){
        if(c==exitcommand){
            destroyapp(false);
            notifydestroyed();
        }
        else if (c==okcommand){
           
            amycanvas=new mycanvas();
            adisplay.setcurrent(amycanvas);
        }
           
        }
   
   
   
    public class mycanvas extends canvas implements commandlistener{
       
        string keyname=””;
        public mycanvas(){
            backcommand=new command(“后退”,command.exit,1);
            addcommand(backcommand);
            setcommandlistener(this);
        }
       
        public void paint(graphics g){
           //清除屏幕
            g.setcolor(0xffffff);
            g.fillrect(0,0,getwidth(),getheight());
           
            //设置字体颜色并画出所按键的名称
            g.setcolor(0);
            g.drawstring(keyname,100,100,graphics.left|graphics.bottom);
        }
       
        public void commandaction(command c , displayable d){
            if (c==backcommand){
                hidenotify();
                //adisplay.setcurrent(atextbox);
            }
           
        }
       
        public void keypressed(int keycode){
            keyname=getkeyname(keycode);
            repaint();
        }
        
        protected void hidenotify(){
            adisplay.setcurrent(showalert,atextbox);
        }
    }
}

通过这个程序,主要练习了keypress的用法。此外,还有hidenotify()的用法,但shownotify()的用法还不是很清楚。

hidenotify()是在画布被从显示屏移除后,实现立刻调用该方法。

shonotify()是在画布显示在显示屏之前系统将先调用该方法。

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 我的J2ME编程练习(8)——Canvas3-JSP教程,Java基础
分享到: 更多 (0)