【发布时间】:2013-12-14 07:16:16
【问题描述】:
当用户名或密码文本框为空时,我试图显示一个消息框,但是当我运行项目时,唯一显示的文本框是“JOptionPane.showMessageDialog(null,"您的用户名或密码不正确");”请帮忙,谢谢!
private void jButton1ActionPerformed(ActionEvent evt) {
String user=txtUsername.getText();
char[] pass=txtPassword.getPassword();
if(user == null) {
JOptionPane.showMessageDialog(null,"Username Field is empty");
} else if(pass==null) {
JOptionPane.showMessageDialog(null,"Password Field is empty");
} else {
String sql="select * from account where username=? and password=?";
try{
pst=conn.prepareStatement(sql);
pst.setString(1,txtUsername.getText());
pst.setString(2,txtPassword.getText());
rs=pst.executeQuery();
if (rs.next()) {
GridlockMain a=new GridlockMain();
a.setVisible(true);
} else {
JOptionPane.showMessageDialog(null,"Your Username or Password is incorrect");
txtUsername.setText(null);
txtPassword.setText(null);
}
} catch (SQLException e) {
JOptionPane.showMessageDialog(null,e);
}
}
}
【问题讨论】:
标签: java netbeans login jtextfield messagebox