我想運行一個小例子,我從這裏找到http://docs.oracle.com/javase/7/docs/api/javax/swing/Timer.html。但是,我得到Type mismatch: cannot convert from void to Timer
在計時器=新的計時器.....線。我希望有人能幫助我。計時器編譯問題
int delay = 1000; //milliseconds
ActionListener taskPerformer = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
//...Perform a task...
}
};
new Timer(delay, taskPerformer).start();
謝謝
我的代碼;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.Timer;
public class MyTimerTest
{
private JFrame frame = new JFrame();
Container contentPane = frame.getContentPane();
Timer timer;
int delay = 1000; //a second
public MyTimerTest()
{
}
public void runTimer()
{
ActionListener taskPerformer = new ActionListener()
{
@Override
public void actionPerformed(ActionEvent arg0) {
}
};
timer = new Timer(delay, taskPerformer).start();
}
/**
* @param args
*/
public static void main(String[] args)
{
}
}
請出示*完整*碼你嘗試。可能有多種原因導致失敗,但它們需要更多的上下文。 – 2012-03-12 18:56:52