我有一个Swing GUI,我限制用户注册,以便用户名和密码不能相同。我使用JoptionPane
的任务用下面的代码:JoptionPane验证
public void actionPerformed(ActionEvent e) {
String username = tuser.getText();
String password1 = pass1.getText();
String password2 = pass2.getText();
String workclass = wclass.getText();
Connection conn = null;
try {
if(username.equalsIgnoreCase(password1)) {
JOptionPane.showMessageDialog(null,
"Username and Password Cannot be the same. Click OK to Continue",
"Error", JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
...
的问题是,我不得不使用System.exit(0)
;没有它,下一个代码被执行。即使在JOptionPane
猛增之后,注册仍然成功。我不需要系统退出,但我需要用户在验证后保存在注册页面上。做这个的最好方式是什么?有没有其他方便的方法来做到这一点,而不是使用JOptionPane
?
我认为这是最好的选择,因为它避免了循环会产生的无用负载。 – 2012-07-31 09:52:00
我完全同意你的SoboLan。它工作得很好......我想要的方式。 – ErrorNotFoundException 2012-07-31 10:01:51