[语法] 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