import javax.microedition.midlet.midlet;
import java.util.*;
/*
* 创建日期 2005-10-8
*
* todo 要更改此生成的文件的模板,请转至
* 窗口 - 首选项 - java - 代码样式 - 代码模板
*/
/**
* @author snail
*
* todo 要更改此生成的类型注释的模板,请转至
* 窗口 - 首选项 - java - 代码样式 - 代码模板
*/
public class mytimertask extends timertask {
private midlet midlet;
/**
*
*/
public mytimertask(midlet midlet) {
// todo 自动生成构造函数存根
system.out.println("mytimertask contructor");
this.midlet = midlet;
}
public void run(){
system.out.println("run() called");
midlet.resumerequest();
}
}
import javax.microedition.midlet.midlet;
import javax.microedition.lcdui.*;
import java.util.*;
import javax.microedition.midlet.midletstatechangeexception;
/*
* 创建日期 2005-10-8
*
* todo 要更改此生成的文件的模板,请转至
* 窗口 - 首选项 - java - 代码样式 - 代码模板
*/
/**
* @author snail
*
* todo 要更改此生成的类型注释的模板,请转至
* 窗口 - 首选项 - java - 代码样式 - 代码模板
*/
public class midlettest extends midlet implements commandlistener{
private timer timer;
private mytimertask mtk;
private command exit;
/**
*
*/
public midlettest() {
system.out.println("midlettest constructor");
//初始化timer对象
timer = new timer();
}
/* (非 javadoc)
* @see javax.microedition.midlet.midlet#startapp()
*/
protected void startapp() throws midletstatechangeexception {
// todo 自动生成方法存根
system.out.println("startapp called");
exit = new command("exit", command.exit, 1);
form f = new form("midlettest");
string s = new string("i'll come back soon!");
f.append(s);
f.addcommand(exit);
f.setcommandlistener(this);
display.getdisplay(this).setcurrent(f);
try{
//画面停留4秒 即活动状态 时间为4秒
thread.sleep(4000);
}catch(exception e){}
system.out.println("ready to paused");
try{
mtk = null;
//获得当前midlet基类的引用(向上转型)
mtk = new mytimertask(this);
//执行该任务等待 2秒
timer.schedule(mtk, 2000);
//请求进入暂停状态
pauseapp();
notifypaused();
}catch(exception e){}
}
/* (非 javadoc)
* @see javax.microedition.midlet.midlet#pauseapp()
*/
protected void pauseapp() {
// todo 自动生成方法存根
system.out.println("pauseapp called");
}
/* (非 javadoc)
* @see javax.microedition.midlet.midlet#destroyapp(boolean)
*/
protected void destroyapp(boolean arg0)throws midletstatechangeexception {
// todo 自动生成方法存根
system.out.println("destroyapp called:" + arg0);
//停止timer ,和timertask合同期满,脱离关系
timer.cancel();
}
public void commandaction(command c, displayable d){
if(c == exit){
try{
destroyapp(false);
notifydestroyed();
}catch(midletstatechangeexception e){}
}
}
}
mtk = new mytimertask(this);
timer.schedule(mtk, 2000);
try{
mtk = null;
//获得当前midlet基类的引用(向上转型)
mtk = new mytimertask(this);
//执行该任务等待 2秒
timer.schedule(mtk, 2000);
//请求进入暂停状态
pauseapp();
notifypaused();
}catch(exception e){} Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器