我在看《JAVA编程思想》的多线程一章中好象有!自己找找吧!
解决方案 »
- 关于边框
- 求救啊,为什么我那么 javaw.exe 驻在内存里,无法释放????
- 急急急,图片打印问题
- menuitem的问题
- 关于swing的很简单的一个加按钮问题
- non-static method doSaveDataImexport() cannot be referenced from a static context 请问是什么意思?我该怎样解决?代码见内,谢谢
- JTable--我通过Socket将数据库中的数据传送到了客户端,JTable不能正常显示。
- 我开发的JSP可视开发工具现已放到FTP上,欢迎下载及试用,一定不让你失望!结分!
- 如何转码
- C#程序的速度和Java 程序的速度?
- 和DES有关的JAVA问题,有兴趣的请进
- 能不能给我一些输出输入处理的例子呀
详情请看我的java技术专栏
www.csdn.net/Author/turbochen
中的<<Java的秘密:AWT机器人>>
至于延时,我好像没有听说过
interface TimerAble
{
void onTimer();
}
class Timer extends Thread
{
private TimerAble ta;
private long interval;
private boolean stop = false;
public Timer( TimerAble ta,long inerval )
{
this.ta = ta;
this.inerval = inerval;
}
protected void run()
{
while( stop != true )
{
ta.onTimer();
Thread.sleep( interval );
}
}
public void stop()
{
this.stop = true;
}
public void start()
{
this.stop = false;
super.start();
}
}
class MyApp extends Object implements TimerAble
{
protected void onTimer()
{
//The code want to run on timer.
}
public static void main( String[] args )
{
MyApp app = new MyApp()
Timer t = new Timer( app,1000 )
t.start();//begin timer
//......
t.stop;//stop timer
}
}
interface TimerAble
{
void onTimer();
}
class Timer extends Thread
{
private TimerAble ta;
private long interval;
private boolean stop = false;
public Timer( TimerAble ta,long inerval )
{
this.ta = ta;
this.inerval = inerval;
}
protected void run()
{
while( stop != true )
{
ta.onTimer();
Thread.sleep( interval );
}
}
public void stop()
{
this.stop = true;
}
public void start()
{
this.stop = false;
super.start();
}
}
class MyApp extends Object implements TimerAble
{
protected void onTimer()
{
//The code want to run on timer.
}
public static void main( String[] args )
{
MyApp app = new MyApp()
Timer t = new Timer( app,1000 )
t.start();//begin timer
//......
t.stop;//stop timer
}
}
jdk1.3以后支持这个操作,实现原理和我上面写的差不错。java.util.Timer; = Timer
java.util.TimerTask; = TimerAble