midletdemo.java~5~
来自「J2ME高级用户界面的学习代码」· JAVA~5~ 代码 · 共 93 行
JAVA~5~
93 行
//MIDletDemo.javapackage ORA.ch3;import java.util.Timer;import java.util.TimerTask;import javax.microedition.midlet.MIDlet;import javax.microedition.midlet.MIDletStateChangeException;public class MIDletDemo extends MIDlet{ private boolean started = false; private Thread thread; private int timerInterval; private Timer timer; private TimerTask task; public MIDletDemo() { System.out.println("Constructor Executed!"); String interval = getAppProperty("Timer-Interval"); timerInterval = Integer.parseInt(interval); System.out.println("Timer interval is " + interval); } protected void startApp()throws MIDletStateChangeException { if(!started) { started = true; System.out.println("startApp called for the first time!"); startTimer(); } else { System.out.println("startApp called following pause!"); } synchronized (this) { if(thread == null) { thread = new Thread() { public void run() { System.out.println("Thread running!"); while(thread == this) { try{ Thread.sleep(1000); System.out.println("Thread still alive!"); }catch(InterruptedException ex){ } } System.out.println("Thread terminating!"); } }; } }; thread.start(); } protected void pauseApp() { System.out.println("pauseApp called!"); synchronized (this) { if(thread != null) { thread = null; } } } protected void destroyedApp(boolean uncontional) throws MIDletStateChangeException { System.out.println("destroyApp called - unconditional = " + unconditional); if(thread != null) { Thread bgThread = thread; thread = null; try{ bgThread.join(); }catch(InterruptedException ex){ } } stopTimer(); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?