这是CoreJava书上的一个例子,/**
@version 1.00 2000-04-13
@author Cay Horstmann
*/import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.Timer;
// to resolve conflict with java.util.Timerpublic class TimerTest
{
public static void main(String[] args)
{
ActionListener listener = new TimePrinter(); // construct a timer that calls the listener
// once every 10 seconds
Timer t = new Timer(1000, listener);
t.start(); JOptionPane.showMessageDialog(null, "Quit program?"); //去掉
System.exit(0); //这两行
}
}class TimePrinter implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
Date now = new Date();
System.out.println("At the tone, the time is " + now);
Toolkit.getDefaultToolkit().beep();
}
}
每隔1秒,在屏幕上显示一条语句,可是我去掉如下两行
JOptionPane.showMessageDialog(null, "Quit program?");
System.exit(0);
为什么就不显示了呢,我觉得这两行和Timer类没什么关系的啊
@version 1.00 2000-04-13
@author Cay Horstmann
*/import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.Timer;
// to resolve conflict with java.util.Timerpublic class TimerTest
{
public static void main(String[] args)
{
ActionListener listener = new TimePrinter(); // construct a timer that calls the listener
// once every 10 seconds
Timer t = new Timer(1000, listener);
t.start(); JOptionPane.showMessageDialog(null, "Quit program?"); //去掉
System.exit(0); //这两行
}
}class TimePrinter implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
Date now = new Date();
System.out.println("At the tone, the time is " + now);
Toolkit.getDefaultToolkit().beep();
}
}
每隔1秒,在屏幕上显示一条语句,可是我去掉如下两行
JOptionPane.showMessageDialog(null, "Quit program?");
System.exit(0);
为什么就不显示了呢,我觉得这两行和Timer类没什么关系的啊
它在这里只起到了一个让程序不继续向下运行的作用