screentest.java

来自「《精彩的手机UI例程.zip》是很好的手机编辑软件」· Java 代码 · 共 53 行

JAVA
53
字号

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

public class ScreenTest extends MIDlet {
    private Display display;
    private Form s1;
    private Form s2;
    public ScreenTest() {
        s1 = new Form("Screen 1");
        s2 = new Form("Screen 2");   
        Ticker t= new Ticker("This is a test for switching screen. "+
                             "Screen 1 and 2 are switched every 5 seconds.");
        s1.setTicker(t);
        s2.setTicker(t);
    }
    public void startApp() throws MIDletStateChangeException {
        display=Display.getDisplay(this);
        display.setCurrent(s1);
        new Thread(new ScreenTestRun()).start();
    }

    /**
     * Pause the MIDlet
     */
    public void pauseApp() {
    }

    /**
     * Called by the framework before the application is unloaded
     */
    public void destroyApp(boolean unconditional) {
	display=null;
        s1=null;
        s2=null;
    }
    
    class ScreenTestRun implements Runnable {
        public void run() {
            while(true) {
                try {
                    Thread.sleep(5000);
                    if(display.getCurrent()==s1) {
                        display.setCurrent(s2);
                    }
                    else {
                        display.setCurrent(s1);
                    }
                }catch(Exception e){}
            }
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?