import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.Timer;
public class TimerTest {
public static void main(String[]args){
ActionListener listener=new TimerPrinter();
Timer t=new Timer(1000,listener);
t.start();
JOptionPane.showMessageDialog(null,"Quit program?");
System.exit(0);
}}
class TimerPrinter 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?");
    这句话只负责打印“Quit program?”,只会有一个确定按钮让你点
    你应该用
    int a =JOptionPane.ConfirmDialog(null,"Quit program?","提示",JOptionPane.YES_NO_OPTION);
    if(a ==JOptionPane.YES_OPTION){System.exit(0);}
    这样写就可以判断了。选择yes就退出,
      

  2.   

    JOptionPane.showMessageDialog(null,"Quit program?"); 记住,这是一种“阻塞式”的对话框。