《Java2图形设计卷II:Swing》配套光盘源码
源代码在线查看: test.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test implements ActionListener {
private int seconds=1;
public Test() {
Timer oneSecondTimer = new Timer(1000, this);
oneSecondTimer.addActionListener(new SecondListener());
oneSecondTimer.addActionListener(new ThirdListener());
oneSecondTimer.start();
}
public void actionPerformed(ActionEvent e) {
if(seconds == 0)
System.out.println("Time: " + seconds + " second");
else
System.out.println("Time: " + seconds + " seconds");
seconds++;
}
public static void main(String args[]) {
new Test();
while(true);
}
}
class SecondListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
System.out.println("Second Listener");
}
}
class ThirdListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
System.out.println("Third Listener");
}
}