再来一次atm机 用文本做的

package BAIBAI;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileReader;
import java.util.Properties;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import BAOBAO.Mybutton;
import BAOBAO.Txt;

public class login extends JFrame{
private Txt nametxt=new Txt("用户名", 50, 50, this);
private Txt pwdtxt=new Txt("密码", 50, 100, this);
private int count;
/**
* 创建资源对象
*/
public static Properties pr=new Properties();
static{
try{
pr.load(new FileReader("Atm.txt"));
}
catch(Exception e){
System.out.println("文件未找到");
}
}
public login(){
this.setLayout(null);
Mybutton mm=new Mybutton("登陆", 70, 180, this);
Mybutton qq=new Mybutton("取消", 70, 240, this);
mm.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
/**
* 获得文本框里面的文本
*/
String x=nametxt.getText();
String y=pwdtxt.getText();
/**
* 获得资源文件里面的文本
*/
String filename=pr.getProperty("username");
String filepwd=pr.getProperty("pwd");
if(x.equals(filename)&&y.equals(filepwd)){
JOptionPane.showMessageDialog(null, "登陆成功");
login.this.dispose();
Newframe n=new Newframe();
}else{
JOptionPane.showMessageDialog(null, "登陆失败");
}
count++;
if(count>3){
JOptionPane.showMessageDialog(null, "非法用户");
System.exit(0);
}
}
});

qq.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "谢谢使用,再见");
System.exit(0);
}
});
this.setSize(400,500 );
this.setVisible(true);
this.setDefaultCloseOperation(3);
this.setLocationRelativeTo(null);
}


public static void main(String[] args) {
login l=new login();

}

}

转载于:https://www.cnblogs.com/oushiyang/p/5366304.html

你可能感兴趣的:(再来一次atm机 用文本做的)