我想在用户关闭下面的对话框时终止执行
String firstNumber = JOptionPane.showInputDialog("Enter the first Number");
答案 0 :(得分:0)
首先, JOptionPane 没有关闭事件。
幸运的是 JOptionPane 。 showInputDialog (“message”)如果用户按下其中一个关闭按钮,则返回 null :
import javax.swing.JOptionPane;
public class TestClass
{
public static void main (String[] args)
{
String firstNumber = JOptionPane.showInputDialog("Enter the first Number");
if (firstNumber == null)
{
System.out.println("X or Close was pressed.");
System.exit(0);
}
else
{
System.out.println("OK was pressed.");
}
}
}