




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、package hxf;/*创建主程序*/import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.GroupLayout;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.WindowConstants;class MainFrame extends JFrame public JButton checked; public JButton cunkuan; public JBu
2、tton quit; public JButton qukuan; public JButton reset; public MainFrame() / initComponents(); / this.setLocationRelativeTo(null); initComponents(); / 初始化窗口this.setLocationRelativeTo(null); / 让窗口处于居中位置this.setVisible(true); / 使窗口显示出来 / this.setVisible(false); /* 控件初始化*/ private void initComponents()
3、 cunkuan = new JButton(); qukuan = new JButton(); checked = new JButton(); reset = new JButton(); quit = new JButton();setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setTitle(ATM柜员模拟程序);setName(mianframe); setResizable(false); cunkuan.setText(存款); cunkuan.addActionListener(new ActionListen
4、er() public void actionPerformed(ActionEvent evt) cunkuanActionPerformed(evt); );qukuan.setText(取款); qukuan.addActionListener(new ActionListener() public void actionPerformed(ActionEvent evt) qukuanActionPerformed(evt); );checked.setText(查询); checked.addActionListener(new ActionListener() public voi
5、d actionPerformed(ActionEvent evt) checkedActionPerformed(evt); );reset.setText(修改密码); reset.addActionListener(new ActionListener() public void actionPerformed(ActionEvent evt) resetActionPerformed(evt); );quit.setText(退出); quit.addActionListener(new ActionListener() public void actionPerformed(Acti
6、onEvent evt) quitActionPerformed(evt); );GroupLayout layout = new GroupLayout(getContentPane(); /GroupLayout它将组件按层次分组,以决定它们在 Container 中的位置 getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup(
7、) .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(cunkuan) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 105, Short.MAX_VALUE) .addComponent(reset) .addGroup(javax.swing.G
8、roupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(qukuan) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 143, Short.MAX_VALUE) .addComponent(quit) .addComponent(checked) .addContainerGap() ); layout.setVerticalGroup( layout.createParallelGroup(javax.sw
9、ing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(46, 46, 46) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(cunkuan) .addComponent(reset) .addGap(51, 51, 51) .addGroup(layout.createParallelGroup(javax.swing.GroupLayou
10、t.Alignment.BASELINE) .addComponent(quit) .addComponent(qukuan) .addGap(57, 57, 57) .addComponent(checked) .addGap(39, 39, 39) ); pack(); private void quitActionPerformed(ActionEvent evt) LoginFrame load=new LoginFrame(); load.setVisible(true); this.setVisible(false); private void resetActionPerform
11、ed(ActionEvent evt) Setpw setpw=new Setpw(null);setpw.setVisible(true);this.setVisible(false); private void checkedActionPerformed(ActionEvent evt) Display dis=new Display(null); dis.setVisible(true); this.setVisible(false); private void qukuanActionPerformed(ActionEvent evt) Take take=new Take(null
12、); take.setVisible(true); this.setVisible(false); private void cunkuanActionPerformed(ActionEvent evt) Input input=new Input(null); input.setVisible(true); this.setVisible(false); /* 创建账户 */public class Account private int count = 10000; / 初始账户余额10000private String account = 1; / 初始账号private String
13、password = 1; / 初始密码public Account() public void setpw(String password) this.password = password;public void deccount(int money) count -= money; / 取钱public void reccount(int money) count += money; /存钱public int get() return count;public String getaccount() / 账号return account;public String getpw() re
14、turn password;package hxf;import java.awt.BorderLayout;import java.awt.GridLayout;import java.awt.event.ActionEvent;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.W
15、indowConstants;/* 显示余额界面 */public class Display extends JFrame public JButton back;private JLabel jL1;public JTextField jT1;public JButton quit;public JButton qukuan;Account myAccount; / 这个是便以传数值的public Display(Account myaccount) this.myAccount = myaccount;initComponents(); / 初始化窗口, 就是把窗口画出来 jT1.set
16、Text(String.valueOf(myaccount.get(); /获得 用户 为标题this.setLocationRelativeTo(null);this.setVisible(true);public void set(String str) jT1.setText(str);private void initComponents() jL1 = new JLabel();jT1 = new JTextField(15);quit = new JButton();back = new JButton();back.setIcon(new ImageIcon(xiaofangIm
17、age/back.png);qukuan = new JButton();qukuan.setIcon(new ImageIcon(xiaofangImage/qukuan.png);setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);jL1.setText(您的余额为:);jL1.setIcon(new ImageIcon(xiaofangImage/money.png);jT1.setEditable(false);quit.setText(退出);quit.setIcon(new ImageIcon(xiaofangIma
18、ge/exit.png);JPanel p1 = new JPanel();p1.add(jL1);p1.add(jT1);JPanel p2 = new JPanel();JPanel p3 = new JPanel();JPanel p4 = new JPanel();JPanel p5 = new JPanel();p3.add(qukuan);p4.add(back);p5.add(quit);p2.setLayout(new GridLayout(3,1); / 把它分成3行1列p2.add(p3); p2.add(p4);p2.add(p5);this.getContentPane
19、().add(p1,BorderLayout.NORTH); /放在北方this.getContentPane().add(p2,BorderLayout.CENTER);/ 放在下面this.setSize(300, 270);/以上是使用jpanel混合布局, 三个JPanel 分为3行1列, 再 把p1, 放在北方,p2 ,放在下面quit.addActionListener(new java.awt.event.ActionListener() / 退出按钮的事件, 只要点它, 就关闭窗口了public void actionPerformed(java.awt.event.Actio
20、nEvent evt) quitActionPerformed(evt););back.setText(返回); / 返回按钮的事件, 只要点它, 就让当前的窗口不可见back.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) backActionPerformed(evt););qukuan.setText(取款); /取款按钮的事件qukuan.addActionListener(new java.awt.even
21、t.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) qukuanActionPerformed(evt););private void qukuanActionPerformed(ActionEvent evt) new Take(myAccount); /出现一个取款窗口, 并让当前窗口不可见this.setVisible(false);private void quitActionPerformed(ActionEvent evt) this.dispose(); / 也是让自己不可见
22、private void backActionPerformed(ActionEvent evt) this.setVisible(false); / 当自己不可见package hxf;import java.awt.BorderLayout;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;
23、import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.WindowConstants;class Input extends JFrame private JButton clear;private JButton commit;private JLabel jL1;private JTextField jT1;String str = ;private Account myAccount;public Input(Account myA
24、ccount) this.myAccount = myAccount;initComponents();this.setVisible(true);this.setLocationRelativeTo(null);this.setResizable(false);private void initComponents() jL1 = new JLabel();jT1 = new JTextField(15);commit = new JButton();clear = new JButton();setDefaultCloseOperation(WindowConstants.DISPOSE_
25、ON_CLOSE);jL1.setText(存款金额:);commit.setText(确认);commit.addActionListener(new ActionListener() public void actionPerformed(ActionEvent evt) commitActionPerformed(evt););clear.setText(清除);JPanel p1 = new JPanel();JPanel p2 = new JPanel();p1.add(jL1);p1.add(jT1);p2.add(commit);p2.add(clear);JPanel p3 =
26、 new JPanel();/分为2行1列p3.setLayout(new GridLayout(2, 1, 20, 30);p3.add(p1);p3.add(p2);this.getContentPane().add(p3, BorderLayout.CENTER);this.setSize(300, 270);clear.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) clearActionPerformed(
27、evt););private void clearActionPerformed(ActionEvent evt) str = ;jT1.setText(str);private void commitActionPerformed(java.awt.event.ActionEvent evt) if (Integer.parseInt(jT1.getText() % 100 = 0) / 数值不能是字符, 必须是100的倍数int a = Integer.parseInt(jT1.getText();if (a 0)JOptionPane.showMessageDialog(null, 存款
28、不能为负数, 出错, 1);elsemyAccount.reccount(a);int result = javax.swing.JOptionPane.showConfirmDialog(null,是否显示余额?, , javax.swing.JOptionPane.YES_NO_OPTION,javax.swing.JOptionPane.QUESTION_MESSAGE);if (result = javax.swing.JOptionPane.YES_OPTION) str = ;jT1.setText(str);new Display(myAccount);this.setVisib
29、le(false); else new MainFrame();this.setVisible(false); else JOptionPane.showMessageDialog(null,存款金额必须为100的整数倍! + n请确认你的金额, 出错提示, 1);jT1.setText();package hxf;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.ImageIcon;import javax.s
30、wing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextField;import javax.swing.WindowConstants;/* 登录界面 */public class LoginFrame extends JFrame public JPasswordField Jpasswor
31、d;public JTextField accountnum;public JButton commit;private JLabel jL1;private JLabel jL2;private JPanel p1;private JPanel p2;private JPanel p3;public static void main(String args) LoginFrame loginFrame = new LoginFrame();loginFrame.setVisible(true);public LoginFrame() initComponents(); / 初始化窗口this
32、.setLocationRelativeTo(null); / 让窗口处于居中位置this.setVisible(true); / 使窗口显示出来private void initComponents() / jl1, acccountnum 放在p1 面板中/ jl2 jpassword 放在p2面板中/ commint放在p3面板中/ 把p1 , p2 , p3放在p4 面板中, 按照3行1列,网格布局/ 最后把p4放在窗口中this.setIconImage(new ImageIcon(xiaofangImage/bank.png).getImage();jL1 = new JLabel
33、();jL2 = new JLabel();accountnum = new JTextField(10); / 设置长度commit = new JButton();Jpassword = new JPasswordField(10);p1 = new JPanel();p2 = new JPanel();p3 = new JPanel();setTitle(ATM柜员模拟程序); / 窗口标题setResizable(false); / 禁止使用最大化jL1.setText(账 号:);jL1.setIcon(new ImageIcon(xiaofangImage/userName.png
34、); / 加图标jL2.setText(密 码:);jL2.setIcon(new ImageIcon(xiaofangImage/password.png);commit.setText(确定);/ 这个是确定按钮的事件处理/ 把acccount , password内容拿出来 , 如果是空, 就出对话框 提示, 不能为空,/ 如果不是空的, 就与123, 密码也是123判断是不是,/ 是就出对话框提示成功, 不是就提示失败对话框, 再清空内容, 重新输入commit.addActionListener(new ActionListener() / 判读自己不能不空的, 并有对话框说明pub
35、lic void actionPerformed(ActionEvent e) if (accountnum.getText().equals()& new String(Jpassword.getPassword().equals() JOptionPane.showMessageDialog(null, 不能为空);return; else /如果密码对了, 就把主窗口出现, 并让自己为不见if (accountnum.getText().equals(new Account().getaccount()& new String(Jpassword.getPassword().equals
36、(new Account().getpw() JOptionPane.showMessageDialog(LoginFrame.this,欢迎使用ATM柜员模拟系统, 欢迎, 1);MainFrame m = new MainFrame();LoginFrame.this.dispose(); else JOptionPane.showMessageDialog(LoginFrame.this,登录失败,请重新输入, 出错提示, 1);accountnum.setText(); / 密码不对, 就对话框,警告 , 并清空Jpassword.setText(););commit.setIcon(
37、new ImageIcon(xiaofangImage/login.png);p1.add(jL1);p1.add(accountnum);p2.add(jL2);p2.add(Jpassword);p3.add(commit);JPanel p4 = new JPanel();p4.setLayout(new GridLayout(3, 1);p4.add(p1);p4.add(p2);p4.add(p3);this.getContentPane().add(p4);setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);/ 窗口关闭事
38、件this.setSize(250, 200); / 设置大小this.setVisible(true); / 设置可见package hxf;import java.awt.GridLayout;import java.awt.event.ActionEvent;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JPasswordFie
39、ld;/* 修改密码 */public class Setpw extends JFrame public JButton commit;public JLabel commitpw;public JPasswordField jPwcommit;public JPasswordField jPwnew;public JPasswordField jPwold;public JLabel newpw;public JLabel oldpw;public JButton quit;public Account myaccount;public Setpw(Account myaccount) t
40、his.myaccount = myaccount;initComponents();this.setResizable(false);this.setLocationRelativeTo(null);this.setVisible(true);private void initComponents() oldpw = new JLabel();newpw = new JLabel();commitpw = new JLabel();jPwold = new JPasswordField(15);jPwnew = new JPasswordField(15);jPwcommit = new J
41、PasswordField(14);commit = new javax.swing.JButton();quit = new javax.swing.JButton();setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);oldpw.setText(旧密码:);newpw.setText(新密码:);commitpw.setText(确认密码:);commit.setText(确认);JPanel p1 = new JPanel();JPanel p2 = new JPanel();JPanel p3
42、= new JPanel();JPanel p4 = new JPanel();p1.add(oldpw);p1.add(jPwold);p2.add(newpw);p2.add(jPwnew);p3.add(commitpw);p3.add(jPwcommit);p4.add(commit);p4.add(quit);this.setLayout(new GridLayout(4, 1, 5, 5);/布局: 分为4个panel, 最后为4行1列, 间隙为5, 5 this.getContentPane().add(p1);this.getContentPane().add(p2);this
43、.getContentPane().add(p3);this.getContentPane().add(p4);this.setSize(300, 270);/设置的事件commit.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) commitActionPerformed(evt););quit.setText(退出);/退出的事件quit.addActionListener(new java.awt.event.
44、ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) quitActionPerformed(evt););private void commitActionPerformed(ActionEvent evt) boolean flag = false;/ 标志密码不能出现全部相同的数字if (!jPwold.getText().equals(myaccount.getpw() JOptionPane.showMessageDialog(null, 你输入的密码与老密码不匹配!, 错误提示, 1
45、);/ 1是符号/ 二是标题 else if (jPwnew.getText().length() 6)JOptionPane.showMessageDialog(null, 新密码长度必须大于或等于6位, 错误提示, 1);else / 用一个循环来查询密码是否全部一样for (int i = 0; i jPwnew.getText().length(); i+) if (jPwnew.getText().charAt(0) = jPwnew.getText().charAt(i)flag = true;else flag = false;break;/ 密码全部一样则给出提示if (fla
46、g)JOptionPane.showMessageDialog(null, 密码不能全都相同, 错误提示, 1);/ 以上情况都没出现则修改成功else if (jPwold.getText().equals(myaccount.getpw()& jPwnew.getText().equals(jPwcommit.getText() myaccount.setpw(jPwnew.getText();JOptionPane.showMessageDialog(null, 密码修改成功,请记住你的新密码, , 1);this.dispose();private void quitActionPer
47、formed(java.awt.event.ActionEvent evt) /出现登录窗口new LoginFrame();package hxf;import java.awt.BorderLayout;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.
48、JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.WindowConstants;/* 取款界面 */public class Take extends JFrame public JButton back;public JButton clear;public JButton commit;private JLabel jL1;public JTextField jT1;public JButton quit;String str = ;private Account myaccount;publ
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025-2030国内箱包行业市场发展分析及竞争格局与投资机会研究报告
- 2025-2030国内油墨行业市场发展现状及发展前景与投资机会研究报告
- 2025-2030国内化学肥料行业市场深度调研及发展前景与投资机会研究报告
- 2025-2030哑侍者电梯行业市场现状供需分析及投资评估规划分析研究报告
- 2025-2030吸尘器市场占有率调查及未来需求消费规模预测研究报告
- 2025-2030可再生离网能源收集行业市场现状供需分析及投资评估规划分析研究报告
- 2025-2030医用消毒袋市场需求现状调研及未来销售趋势预测研究报告
- 2025-2030包装印刷行业风险投资发展分析及投资融资策略研究报告
- 公牛托养合同样本
- 2025-2030全球及中国高密度磁盘箱行业市场现状供需分析及投资评估规划分析研究报告
- 铝合金门窗施工组织设计方案
- 高中生议论文写作有效教学的策略探讨
- 循环流化床锅炉床温的检修与维护
- 《易经》养生的奥秘课件
- 10 夺取抗日战争和人民解放战争的胜利(说课稿)-2022-2023学年道德与法治五年级下册
- 房屋出租分割证明
- 定制制氮机维修方案范本
- 2023年高考新课标Ⅰ卷语文试题分析及2024年高考语文备考策略 课件36张
- 河北省张承高速公路承德段施工标准化管理实施细则隧道篇
- 整合医学模式中国临床心身医学发展医疗健康课件
- 办公用品采购清单2022
评论
0/150
提交评论