使用MIDP底层用户接口API[2]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:

你激活一个canvas是通过调用MIDletDisplay对象的setCurrent方法来实现的。通常在应用的MIDlet类的startApp方法中调用:

// Simple MIDlet
 
import javax.microedition.midlet.*;
 
public class MyMIDlet extends MIDlet {
 
    private Display  display;
    private MyCanvas canvas;
   
    public MyMIDlet(){
        display = Display.getDisplay( this );
        canvas  = new MyCanvas( this );
    }
   
    protected void startApp(){
        display.setCurrent( canvas );
    }
   
    protected void pauseApp(){
    }
  
    protected void destroyApp( boolean unconditional ){
    }
   
    public void exit(){
        destroyApp( true );
        notifyDestroyed();
    }
}

尽管这个MIDlet能工作,它有一个问题:没有明显的方式可以从它退出。你需要引导用户以某种方式输入。有两种方式可以实现:使用行输入事件或使用命令事件。

n                                            Canvas允许使用行输入事件,是通过覆盖canvas类定义的适当的事件发送方法来实现的。事件生成的可用方法有:

n                                            按键(keyPressedkeyRepeated,和keyReleased

n                                            使用指针(pointerPressedpointerDraggedpointerReleased)如果指针在设备上可以使用的话

n                                            显示canvasshowNotifyhideNotify

本文关键:使用MIDP底层用户接口API
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top