public void actionPerformed(ActionEvent e){
java.awt.Dimension dim1=new java.awt.Dimension(1500, 1000);
java.awt.Dimension dim2=new java.awt.Dimension(100, 40);
Map<String, String> map = new HashMap<String , String>();
String path = "D:\\test.txt";
File file = new File(path);
BufferedReader bReader = new BufferedReader(new FileReader(file));
String line = "";
String pc[] = null;
String key = "";
String value = "";
while ((line = bReader.readLine()) != null) {
pc = line.split(",");
key = pc[0];
value = pc[1];
map.put(key, value);
}
Set <String> keySet = map.keySet();
//利用get方法来获取账号和密码对象的文本信息
for (String string2 : keySet)
if(zh.getText().equals(string2)&mm.getText().equals(map.get(string2))){
init2();
login1.dispose();//用dispose关闭登录界面
}
else {
final JFrame tips = new JFrame("提示");
//选择布局类型,定义流式布局的对象,并且设置每个组件之间距离为20
FlowLayout f1 = new FlowLayout(FlowLayout.CENTER,20,20);
tips.setLayout(f1);
JLabel tishi = new JLabel("请正确输入用户名及对应的密码!");
tips.setBounds(220, 8, 50, 300);
tips.add(tishi);
JButton yes = new JButton();
yes.setText("确认");
yes.setBounds(220, 60, 50, 300);
tips.add(yes);
tips.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
tips.setLocationRelativeTo(null);//设置窗口位于屏幕居中位置
tips.setSize(300, 170);
tips.setResizable(true);
tips.setVisible(true);//设置窗体可见
yes.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
tips.dispose();//销毁登陆窗口
}
});
}
}