📄 midletdemo.java~4~
字号:
//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() 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -