用timer类,定时触发某个功能.
不过具体我也没用过,帮你up ------------------------------------------------------
我们还年轻牛奶会有的奶牛也会有的
可天天在 csdn 混这些会有吗 ??
不过具体我也没用过,帮你up ------------------------------------------------------
我们还年轻牛奶会有的奶牛也会有的
可天天在 csdn 混这些会有吗 ??
解决方案 »
- 子类继承父类 是否继承了父类一切非私有的属性和方法?
- java.sql.SQLException: The SQL statement must not be null or empty.
- 大家都来看看,写文件时,如果数据量非常大,怎样在占用固定内存下高效的进行写操作。
- 请问这样的类继承方法对吗?急
- 在java中想通过双引号来区分,怎么样写啊?
- 怎么把cab文件重新打包成jar文件啊?
- 求思路,想用javase写一个游戏的挂机外挂。求思路。
- Runtime.exec();命令行调用连续问题??
- 如何用jdbc函数返回select查询到的整个表
- 问大家一个问题,到底java能开发什么东西呢?
- 如何修改Jubilder中,以常规方式编写程序
- 关于FocusListener的实现,我怎么响应不了,focusLost,focusGained事件啊?
不过具体我也没用过,帮你up ------------------------------------------------------
我们还年轻牛奶会有的奶牛也会有的
可天天在 csdn 混这些会有吗 ??
{
getTimeSet().setCurrentMjdIndex(getTimeSet().getCurrentMjdIndex() + 1);
timeSettings.fireCurrentMjdChange();
timeSettings.Render();
}try
{
forward = new JButton(new ImageIcon(Utils.findResource("images/VCRForward.gif")));
}
catch (java.io.FileNotFoundException e2)
{
e2.printStackTrace(System.err);
forward = new JButton();
}
forward.setName("forward");
forward.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent evt) {
play();
}
});
autorun = new Jbutton()
autorun.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent evt) {
timer = new Timer(true);
TimerTask tt = new TimerTask()
{
public void run()
{
play();
}
};
timer.schedule(tt, 0, 3 * 1000);
}
});
这样行不行?
public void actionPerformed(ActionEvent evt) {
if(timerThread!=null)
return;
timer = new Timer(true);
TimerTask tt = new TimerTask()
{
public void run()
{
timerThread = new TimerThread();
timerThread.run();
}
};
timer.schedule(tt, 0, 3 * 1000);
}
});
stopButton = new Button("stop");
stopButton.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if(timerThread == null)
return;
timerThread.stop();
}
});class TimerThread implements Runnable
{
Timer timer;
public TimerThread()
{
}
public void run()
{
timer = new Timer(true);
TimerTask tt = new TimerTask()
{
public void run()
{
play();
}
};
timer.schedule(tt, 0, 3 * 1000);
}
public void stop()
{
timer.cancel();
}
}
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Date;public class PlayTest
extends JFrame
{
protected TimerThread timerThread = null; public PlayTest()
{
try
{
jbInit();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
PlayTest playTest = new PlayTest();
playTest.setSize(600, 500);
playTest.setVisible(true);
}
private void jbInit() throws Exception
{
JPanel jPanel = new JPanel();
jPanel.setLayout(null); JButton autorun = new JButton("autorun");
autorun.setBounds(20,30, 80, 25);
autorun.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
if (timerThread != null)
return;
timerThread = new TimerThread();
timerThread.run();
}
});
jPanel.add(autorun); JButton stopButton = new JButton("stop");
stopButton.setBounds(20,80, 80, 25);
stopButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
if (timerThread == null)
return;
timerThread.stop();
timerThread = null;
}
});
jPanel.add(stopButton); this.addWindowListener(new java.awt.event.WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
this_windowClosing(e);
}
});
JScrollPane jScrollPane1 = new JScrollPane();
jScrollPane1.getViewport().add(jPanel);
this.getContentPane().add(jScrollPane1);
} private int count = 0;
protected void play()
{
count++;
System.out.println("playing..." + count);
} private void this_windowClosing(WindowEvent e)
{
System.exit(0);
} class TimerThread implements Runnable
{
Timer timer;
public TimerThread()
{
}
public void run()
{
timer = new Timer(true);
TimerTask tt = new TimerTask()
{
public void run()
{
play();
}
};
timer.schedule(tt, 0, 3 * 1000);
}
public void stop()
{
timer.cancel();
}
}}