喜小宝婚宴预订网:按要求修改JAVA程序
来源:百度文库 编辑:高校问答 时间:2024/10/03 15:08:38
import java.util.*;
public class TimerDemo {
public static void main(String[] args) {
class MyTimerTask extends TimerTask //将该类放于main之外、TimerDemo类中,实现同样功能
{
private Timer tm = null;
public MyTimerTask(Timer tm)
{
this.tm = tm;
}
public void run()
{
try
{
Runtime.getRuntime().exec("calc.exe");
}
catch (Exception ex)
{
ex.printStackTrace();
}
tm.cancel();
}
}
Timer tm = new Timer();
tm.schedule(new MyTimerTask(tm),3000,2000);
}
}
public class TimerDemo {
public static void main(String[] args) {
class MyTimerTask extends TimerTask //将该类放于main之外、TimerDemo类中,实现同样功能
{
private Timer tm = null;
public MyTimerTask(Timer tm)
{
this.tm = tm;
}
public void run()
{
try
{
Runtime.getRuntime().exec("calc.exe");
}
catch (Exception ex)
{
ex.printStackTrace();
}
tm.cancel();
}
}
Timer tm = new Timer();
tm.schedule(new MyTimerTask(tm),3000,2000);
}
}
import java.util.*;
public class TimerDemo {
static Timer tm = new Timer();
public static class MyTimerTask extends TimerTask
{
private Timer tm = null;
public MyTimerTask(Timer tm) {
this.tm = tm;
}
public void run() {
try {
Runtime.getRuntime().exec("calc.exe");
} catch (Exception ex) {
ex.printStackTrace();
}
tm.cancel();
}
}
public static void main(String[] args) {
tm.schedule(new TimerDemo.MyTimerTask(tm), 3000, 2000);
}
}
在main中创建MyTimerTask 的实例就行了吧