📄 timertasktest.java
字号:
//TimerTaskTest.java
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;
public class TimerTaskTest extends MIDlet implements CommandListener
{
private Display display;
private Form props;
private StringItem item;
private Command exitCommand = new Command("Exit", Command.EXIT, 1);
public TimerTaskTest()
{
display = Display.getDisplay(this);
}
public void startApp()
{
props = new Form("TimerTask");
item = new StringItem( "Now ", "" );
props.append(item);
props.addCommand(exitCommand);
props.setCommandListener(this);
display.setCurrent(props);
Timer timer = new Timer();
TimerTask task = new ShowTimeTask( item, display );
timer.schedule( task, 0, 1000 ); //每秒钟执行一次
}
public void commandAction(Command c, Displayable s)
{
if (c == exitCommand)
{
destroyApp(false);
notifyDestroyed();
}
}
public void destroyApp(boolean unconditional)
{
}
public void pauseApp()
{
}
}
class ShowTimeTask extends TimerTask
{
private StringItem item;
private Display display;
ShowTimeTask( StringItem item, Display display )
{
this.item = item;
this.display = display;
}
public void run()
{
if( item == null || display == null ) return;
Calendar c = Calendar.getInstance();
int m = c.get( Calendar.MINUTE );
int s = c.get( Calendar.SECOND );
item.setText( m + " : " + s );
if( s == 0 )display.flashBacklight(2000); //每分种闪烁一下
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -