利用GUI界面来编写ATM机
来源:互联网 发布:数据信号避雷器 编辑:程序博客网 时间:2024/05/19 06:17
话不多说,上来就是一堆干货。这个是博主在学习过程中,不断学习到新的方法,来对ATM就行改进。其中,新增加的方法包括了方法的调用、GUI的设计、继承、事件触发、读取/写入数据文件等等一系列方法。是博主在现阶段中学习的一些精髓,希望各位看官在观看的过程中,能指点一二(请用本人现阶段能懂得方法讲解~~),谢谢观看~~
package ATM;
import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.FileReader; import java.io.FileWriter; import java.util.Properties;
import javax.swing.JFrame; import javax.swing.JOptionPane;
public class Atm extends JFrame {
private MyJText Name =new MyJText("用户名",50,50,this);
private MyJText Psw =new MyJText("密码",50,100,this);
public static Properties pro =new Properties();
private int number;
//静态块的使用!要看书174页!
static{ try { pro.load(new FileReader("info")); } catch (Exception e) { System.out.println("文件读取错误"); System.exit(0); } }
public static void SaveProperties(){try {pro.store(new FileWriter("info"), null);} catch (Exception e) {System.out.println("文件未找到");System.exit(0);}}public Atm(){this.setLayout(null);MyButton but =new MyButton("登陆",200,200,this);but.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {String newName = Name.getText();String newPsw = Psw.getText();String OldName = pro.getProperty("userName");String OldPsw = pro.getProperty("password");if(OldName.equals(newName) && OldPsw.equals(newPsw)){JOptionPane.showMessageDialog(null, "登陆成功");Atm.this.dispose();new MyJFrame();}else{JOptionPane.showMessageDialog(null, "登录失败!");Name.setText("");Psw.setText("");}number++;if(number >=3){JOptionPane.showMessageDialog(null, "账号密码错误!");System.exit(0);}}});this.setSize(400,300);this.setVisible(true);this.setDefaultCloseOperation(3);this.setLocationRelativeTo(null);}public static void main(String [] agrs){Atm a =new Atm();}
}
package ATM;
import java.awt.event.ActionEvent; import java.awt.event.ActionListener;
import javax.swing.JFrame; import javax.swing.JOptionPane;
public class ChangeFrame extends JFrame {
private MyJText psw1 = new MyJText("请输入新密码", 50, 50, this);
private MyJText psw2 = new MyJText("确认新密码", 50, 100, this);
private int number;
public ChangeFrame(){this.setLayout(null);MyButton but =new MyButton("改密", 200, 200, this);but.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {String str = Atm.pro.getProperty("password");String Str1 =psw1.getText();String Str2 =psw2.getText();if(Str1.equals(Str2)){str=Str1;JOptionPane.showMessageDialog(null, "改密成功");Atm.pro.setProperty("password", str);Atm.SaveProperties();ChangeFrame.this.dispose();new MyJFrame();}else{JOptionPane.showMessageDialog(null, "两次密码不一致,请修改");psw1.setText("");psw2.setText("");}number++;if(number>=3){JOptionPane.showMessageDialog(null, "密码修改失败");System.exit(0);}}});this.setSize(400, 300);this.setVisible(true);this.setDefaultCloseOperation(3);this.setLocationRelativeTo(null);}public static void main(String [] agrs){ChangeFrame c =new ChangeFrame();}
}
package ATM;
import java.awt.event.ActionEvent; import java.awt.event.ActionListener;
import javax.swing.JFrame; import javax.swing.JLabel;
public class FindFrame extends JFrame{
public FindFrame(){ this.setLayout(null);
String moneyTxt =Atm.pro.getProperty("money");
JLabel jl =new JLabel("余额"+moneyTxt);
jl.setBounds(100, 100, 120, 30);
this.add(jl);
MyButton but =new MyButton("返回",180,190,this);but.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {FindFrame.this.dispose();new MyJFrame();}});this.setSize(400, 300);this.setVisible(true);this.setDefaultCloseOperation(3);this.setLocationRelativeTo(null);}public static void main(String [] agrs){FindFrame f =new FindFrame();}
}
package ATM;
import java.awt.event.ActionEvent; import java.awt.event.ActionListener;
import javax.swing.JFrame; import javax.swing.JOptionPane;
public class GetFrame extends JFrame{
private MyJText jt =new MyJText("请输入取款金额",100,100,this);
public GetFrame(){ this.setLayout(null);
MyButton but =new MyButton("取款",230,150,this);but.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {String OldMoney = Atm.pro.getProperty("money");int a = Integer.parseInt(OldMoney);String newMoney =jt.getText();int b =Integer.parseInt(newMoney);if(b<a){a-=b;JOptionPane.showMessageDialog(null, "取款成功!");Atm.pro.setProperty("money", a+"");Atm.SaveProperties();GetFrame.this.dispose();new FindFrame();}else{JOptionPane.showMessageDialog(null, "取款超过存款!");jt.setText("");}}});this.setSize(400,300);this.setVisible(true);this.setDefaultCloseOperation(3);this.setLocationRelativeTo(null);}public static void main(String [] agrs){GetFrame s=new GetFrame();}
}
package ATM;
import java.awt.event.ActionEvent; import java.awt.event.ActionListener;
import javax.swing.JFrame; import javax.swing.JOptionPane;
public class MyJFrame extends JFrame {
public MyJFrame() {
this.setLayout(null);
MyButton FindFrame = new MyButton("查询", 20, 70, this);MyButton ChangeFrame = new MyButton("改密", 20, 170, this);MyButton SetFrame = new MyButton("存款", 220, 60, this);MyButton GetFrame = new MyButton("取款", 220, 120, this);MyButton ExitFrame = new MyButton("取卡", 220, 180, this);FindFrame.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {MyJFrame.this.dispose();new FindFrame();}});ChangeFrame.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {MyJFrame.this.dispose();new ChangeFrame();}});SetFrame.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {MyJFrame.this.dispose();new SetFrame();}});GetFrame.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {MyJFrame.this.dispose();new GetFrame();}});ExitFrame.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {
// MyJFrame.this.dispose();
// new ExitFrame();
JOptionPane.showMessageDialog(null, "请取回您的卡片!");
System.exit(0);
}});this.setSize(400, 300);this.setVisible(true);this.setDefaultCloseOperation(3);this.setLocationRelativeTo(null);}public static void main(String[] agrs) {MyJFrame jf = new MyJFrame();}
}
package ATM;
import java.awt.event.ActionEvent; import java.awt.event.ActionListener;
import javax.swing.JFrame; import javax.swing.JOptionPane;
public class SetFrame extends JFrame {
private MyJText jt =new MyJText("请输入存款金额",100,100,this);
public SetFrame(){
this.setLayout(null);
MyButton but =new MyButton("存款",230,150,this);but.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {String OldMoney = Atm.pro.getProperty("money");int a = Integer.parseInt(OldMoney);String newMoney =jt.getText();int b =Integer.parseInt(newMoney);a+=b;JOptionPane.showMessageDialog(null, "存款成功!");Atm.pro.setProperty("money", a+"");Atm.SaveProperties();SetFrame.this.dispose();new FindFrame();}});this.setSize(400,300);this.setVisible(true);this.setDefaultCloseOperation(3);this.setLocationRelativeTo(null);}public static void main(String [] agrs){SetFrame s=new SetFrame();}
}
- 利用GUI界面来编写ATM机
- 利用c语言来进行简单的模拟ATM机
- 利用 IDEA 编写 GUI
- 利用 JBuilder 编写 GUI
- 利用JAVA编写可视化界面
- 模拟ATM柜员机界面
- C++编写ATM(1)
- C++编写ATM(2)
- C++编写ATM
- java ATM简单编写
- [初学Python]学习如何编写GUI界面(初级)
- ATM机密码输入界面的编写(终端连接属性)
- 利用Qt为FFmpeg编写前端界面
- 使用PyQt来编写第一个Python GUI程序
- 使用PyQt来编写第一个Python GUI程序
- 使用PyQt来编写第一个Python GUI程序
- 使用PyQt来编写第一个Python GUI程序
- 简单Java小程序----无界面ATM机
- 武当峡谷第一漂之勇涉急流
- 如何优化网站的响应时间
- [kuangbin带你飞]专题七 线段树 C POJ 3468
- linux dirname basename的用法
- Android Studio中的keystore
- 利用GUI界面来编写ATM机
- 企业注册号构造、入库实现原理
- PAT乙级1006
- 《Java多线程编程核心技术》(一)多线程技能
- 2.4.3节练习
- 目标跟踪学习算法之二:DSST
- java Math类
- (学习笔记) Java byte[]转二进制字符串,十六进制字符串的相互转换
- 2016.9.20 在yoya的三个月