JPanel p = new JPanel();
JTextField userName = new JTextField(10);
JPasswordField passWord = new JPasswordField(10);
p.add(new JLabel("Username:"));
p.add(userName);
p.add(new JLabel("Password: "));
p.add(passWord);
JOptionPane.showConfirmDialog(null, p, "Username and password: ", JOptionPane.OK_CANCEL_OPTION);
我的问题是我如何制作如此用户名是用户名,密码是密码,如果你键入正确的用户名和密码,它会启动应用程序,如果不关闭它?
答案 0 :(得分:0)
在你的gui中,
int selectedOption = JOptionPane.showConfirmDialog(null, p, "Username and password: ", JOptionPane.YES_NO_OPTION);
if (selectedOption == JOptionPane.YES_OPTION) {
if (userName.getText().equals("abc") && passWord.getText().equals("abc")) {
//do some action, login success
}
else
{
//do some action, login fail
}
}//end if
else
{
//do some action, means user cancel the login
}