【发布时间】:2011-06-13 11:44:58
【问题描述】:
我创建了一个需要 3 个字段的自定义对话框
public class Test{
public static void main(String args[])
{
JTextField firstName = new JTextField();
JTextField lastName = new JTextField();
JPasswordField password = new JPasswordField();
final JComponent[] inputs = new JComponent[] {
new JLabel("First"),
firstName,
new JLabel("Last"),
lastName,
new JLabel("Password"),
password
};
JOptionPane.showMessageDialog(null, inputs, "My custom dialog",JOptionPane.PLAIN_MESSAGE);
System.out.println("You entered " +firstName.getText() + ", " +lastName.getText() + ", " +password.getText());
}
}
如何检查用户是否已插入所有字段?即使用户关闭它也会显示的对话框
You entered , ,
如果用户关闭对话框而不显示,我想检查用户在字段中的输入并关闭应用程序
"You entered , , "
【问题讨论】:
-
为什么不对这些字段执行
null检查,如果这三个字段中的任何一个为空,请再次显示对话框,指示所有字段都是必需的。 -
谢谢我明白了...但是关闭操作呢