如何检查用户是否在 JDialogBox 中输入了某些内容?
我创建了一个需要 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 , , "
I have created a custom dialog box which requires 3 fields
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());
}
}
How do I check if the user has inserted all fields or not? And even if user close the dialog box it display
You entered , ,
I want to check user input in field and close application if user close dialog box without dsplaying
"You entered , , "
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以检查用户是否已插入所有字段,如下所示:
编辑:
要在关闭对话框后显示消息,您可以这样做:
编辑2:
确定,我想我现在明白你的问题了,试试这个:
You can check if user has inserted all fields or not as follows:
EDIT:
For displaying a message after closing the dialog box, you can do it like:
EDIT2:
OK, I think I understand your question now, try this:
我建议采用不同的方法来界定每个数据。
这样,您就可以知道哪个字段丢失了。
I suggest a different approach of delimiting each datum.
That way, you can tell which field(s) is missing in.
简短的回答,在打印之前检查字符串中是否还有任何内容。
Short answer, check to see if there is anything left in the String before print.