import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class Atm extends JFrame implements ActionListener{
JFrame frame;
JPanel p1,p2,p3,p4,p5;
JLabel l2,l3;
JButton[] b = new JButton[8];
String s[]={"查 询","取 款","存 款","转 账","注销帐户","返 回","退 出","修改密码"};
int i;
int money = 50000;
public Atm() {
frame=new JFrame("我的Atm机");
frame.setSize(400,300);
p1=new JPanel();
p2=new JPanel();
p3=new JPanel();
p4=new JPanel();
p5=new JPanel();
l3=new JLabel();
l3.setIcon(new ImageIcon("1.gif"));
p5.add(l3);
l2=new JLabel();
l2.setIcon(new ImageIcon("123.jpg"));
p4.add(l2);
p2.setLayout(new BorderLayout());
for ( i = 0; i <8; i++) {
b[i] = new JButton(s[i]); }
for(i=0;i<4;i++){
p1.add(b[i]);}
for(i=4;i<8;i++){
p3.add(b[i]);}
for(i=0;i<8;i++){
b[i].addActionListener(this);} //添加监听器
p1.setLayout(new GridLayout(4,1,0,10));
p3.setLayout(new GridLayout(4,1,0,10));
frame.setLayout(new BorderLayout());
frame.getContentPane().add(p1,BorderLayout.WEST); //西
frame.getContentPane().add(p2,BorderLayout.CENTER); //中
frame.getContentPane().add(p3,BorderLayout.EAST); //东
frame.getContentPane().add(p4,BorderLayout.SOUTH); //南
frame.getContentPane().add(p5,BorderLayout.NORTH); //北
frame.pack();
frame.show();
frame.setVisible(true);
frame.setResizable(false);//不可放大
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
JButton jb = (JButton)e.getSource();
JPanel p5=new JPanel();
JLabel l4=new JLabel();
p5.add(l4);
p2.add(p5);
if(jb==b[6]) //退出
{ System.exit(0);}
else if(jb==b[5]){ //返回
Atms Atms=new Atms(); //跳转到登录界面
frame.setVisible(false);
}
else if(jb==b[3]){ //转账
frame.setVisible(false);
String zh = JOptionPane.showInputDialog(null, "请输入账号:");
String is = JOptionPane.showInputDialog(null, "请输入金额:");
if(is != null && is.matches("\\d+"))
{
int input = Integer.parseInt(is);
money += input;
l4.setText("你已成功转账" + input + "元到"+zh+"账号");
frame.setVisible(true);
}
}
else if(jb==b[2]){ //存款
frame.setVisible(false);
String is = JOptionPane.showInputDialog(null, "输入存款额:");
if(is != null && is.matches("\\d+")) {
int input = Integer.parseInt(is);
money += input;
l4.setText("你已经存入" + input + "元");
frame.setVisible(true);
}
}
else if(jb==b[1]){ //取款
frame.setVisible(false);
String is = JOptionPane.showInputDialog(null, "输入取款额:");
int input = Integer.parseInt(is);
if((input%100)!= 0 && input<=10000) {
input = input >= money ? money : input;
money -= input;
l4.setText("你已经取走" + input + "元");
frame.setVisible(true);
}
else
l4.setText("您的当前余额不足!");
}
else if(jb==b[0]){ //查询
JOptionPane.showMessageDialog(null, "当前余额是: " + money);
l4.setText("当前余额: " + money);
}
else if(jb==b[8]){ //修改密码
frame.setVisible(false);
String is = JOptionPane.showInputDialog(null, "新密码:");
frame.setVisible(true);
}
}
public static void main (String[] args) {
new Atm();
}
}
java ATM取款机
需积分: 10 169 浏览量
2010-06-11
15:17:34
上传
评论
收藏 23KB RAR 举报
luzongtong
- 粉丝: 0
- 资源: 5
最新资源
- 937712277954201实习5.word
- 2程序语言基础知识pdf1_1716337722703.jpeg
- 简单的Python示例,演示了如何使用TCP/IP协议进行基本的客户端和服务器通信
- 考试.sql
- keil2 + proteus + 8051.exe
- 1961ee27df03bd4595d28e24b00dde4e_744c805f7e4fb4d40fa3f695bfbab035_8(1).c
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
- windows注册表编辑工具
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
- 校园通行码预约管理系统20240522075502
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈