[語法] ActionListener 問題

作者: gecer (gecer)   2018-01-13 21:49:23
小弟想請問一下 下列的codet重複印出go 但是ActionListener沒有被別指定button
請問ActionListener是不是只要有event dispatch thread 就會被trigger?
import javax.swing.Timer;
import javax.swing.JFrame;
public class MyClass {
public static void main(String[] args) {
Timer t = new Timer(400, new MyF());
t.setRepeats(true);
t.start();
JFrame MyFrame=new JFrame();
MyFrame.setVisible(true);
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class MyF implements ActionListener {
@Override
public void actionPerformed(ActionEvent arg0) {
System.out.println("Go");
}
}
作者: ssccg (23)   2018-01-13 21:59:00
跟button和event dispatch thread都沒關Timer就是用來定時送action event啊先去看看Timer的API說明吧

Links booklink

Contact Us: admin [ a t ] ucptt.com