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();
}
}
好像最后一个语句有没有结果都一样,请问为什么呢???谢谢
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();
}
}
好像最后一个语句有没有结果都一样,请问为什么呢???谢谢
这句话只负责打印“Quit program?”,只会有一个确定按钮让你点
你应该用
int a =JOptionPane.ConfirmDialog(null,"Quit program?","提示",JOptionPane.YES_NO_OPTION);
if(a ==JOptionPane.YES_OPTION){System.exit(0);}
这样写就可以判断了。选择yes就退出,