private void LoginMouseClicked(java.awt.event.MouseEvent evt)
throws IOException {
String name = this.UserName.getText().trim();//获取输入信息
String pwd = this.PassWord.getText().trim();
Properties prop = new Properties();//创建集合
Reader r = new FileReader("user.txt");
prop.load(r);
r.close();
Set set = prop.stringPropertyNames();
//判断用户名是否相同
if (set.contains(name)) {
for (String key : set) { //遍历集合,获取键所对应的值
String value = prop.getProperty(key);
//判断密码是否相同
if(value.contains(pwd)){
dispose();
TextFrame tf = new TextFrame();
tf.setVisible(true);
}
else {
JOptionPane.showMessageDialog(this, "用户名或密码错误,请重新登录!");
dispose();
LoginFrame lf = new LoginFrame();
lf.setVisible(true);
this.UserName.setText("");
this.PassWord.setText("");
break;
}
}
} else {
JOptionPane.showMessageDialog(this, "用户名或密码错误,请重新登录!");
dispose();
LoginFrame lf = new LoginFrame();
lf.setVisible(true);
this.UserName.setText("");
this.PassWord.setText("");
}
} |
|