1、 private void initComponents() 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.addAct
2、ionListener(new ActionListener() public void actionPerformed(ActionEvent evt) cunkuanActionPerformed(evt); ); qukuan.setText(取款 qukuan.addActionListener(new ActionListener() qukuanActionPerformed(evt); checked.setText(查询 checked.addActionListener(new ActionListener() checkedActionPerformed(evt); res
3、et.setText(修改密码 reset.addActionListener(new ActionListener() resetActionPerformed(evt); quit.setText(退出 quit.addActionListener(new ActionListener() quitActionPerformed(evt); GroupLayout layout = new GroupLayout(getContentPane(); /GroupLayout它将组件按层次分组,以决定它们在 Container 中的位置 getContentPane().setLayout(
4、layout); layout.setHorizontalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(cunkuan) .addPreferredGap(javax.swing.LayoutStyle.Co
5、mponentPlacement.RELATED, 105, Short.MAX_VALUE) .addComponent(reset) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(qukuan) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 143, Short.MAX_VALUE) .addComponent(quit) .addComponent
6、(checked) .addContainerGap() ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(46, 46, 46) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGap(51, 51, 51) .addComponent(quit) .addComponent(qukuan) .addGap(57
7、, 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 resetActionPerformed(ActionEvent evt) Setpw setpw=new Setpw(null); setpw.setVisible(true); this
8、.setVisible(false); private void checkedActionPerformed(ActionEvent evt) Display dis=new Display(null); dis.setVisible(true); private void qukuanActionPerformed(ActionEvent evt) Take take=new Take(null); take.setVisible(true); private void cunkuanActionPerformed(ActionEvent evt) Input input=new Inpu
9、t(null); input.setVisible(true);/* 创建账户 */public class Account private int count = 10000; / 初始账户余额10000 private String account = 1; / 初始账号 private String password = / 初始密码 public Account() public void setpw(String password) this.password = password; public void deccount(int money) count -= money; /
10、取钱 public void reccount(int money) count += money; /存钱 public int get() return count; public String getaccount() / 账号 return account; public String getpw() return password;import java.awt.BorderLayout;import java.awt.GridLayout;import javax.swing.ImageIcon;import javax.swing.JLabel;import javax.swin
11、g.JPanel;import javax.swing.JTextField;/* 显示余额界面 */public class Display extends JFrame public JButton back; private JLabel jL1; public JTextField jT1; Account myAccount; / 这个是便以传数值的 public Display(Account myaccount) this.myAccount = myaccount; initComponents(); / 初始化窗口, 就是把窗口画出来 jT1.setText(String.v
12、alueOf(myaccount.get(); /获得 用户 为标题 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(xiaofangImage/back.png); qukuan = new JButton(); qukuan.setIcon(new Imag
13、eIcon(xiaofangImage/qukuan.png setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); jL1.setText(您的余额为: jL1.setIcon(new ImageIcon(xiaofangImage/money.png jT1.setEditable(false); quit.setIcon(new ImageIcon(xiaofangImage/exit.png JPanel p1 = new JPanel(); p1.add(jL1); p1.add(jT1); JPanel p2 = ne
14、w 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().add(p1,BorderLayout.NORTH); /放在北方 this.getContentPane().add(p2,
15、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.ActionEvent evt) quitActionPerformed(evt); ); back.setText(返回 / 返回
16、按钮的事件, 只要点它, 就让当前的窗口不可见 back.addActionListener(new java.awt.event.ActionListener() backActionPerformed(evt); /取款按钮的事件 qukuan.addActionListener(new java.awt.event.ActionListener() qukuanActionPerformed(evt); new Take(myAccount); /出现一个取款窗口, 并让当前窗口不可见 private void quitActionPerformed(ActionEvent evt) t
17、his.dispose(); / 也是让自己不可见 private void backActionPerformed(ActionEvent evt) / 当自己不可见import javax.swing.JOptionPane;class Input extends JFrame private JButton clear; private JButton commit; private JTextField jT1; String str = private Account myAccount; public Input(Account myAccount) this.myAccount
18、= myAccount; this.setResizable(false); commit = new JButton(); clear = new JButton();存款金额: commit.setText(确认 commit.addActionListener(new ActionListener() public void actionPerformed(ActionEvent evt) commitActionPerformed(evt); clear.setText(清除 p2.add(commit); p2.add(clear); /分为2行1列 p3.setLayout(new
19、 GridLayout(2, 1, 20, 30); p3.add(p1); p3.add(p2); this.getContentPane().add(p3, BorderLayout.CENTER); clear.addActionListener(new java.awt.event.ActionListener() clearActionPerformed(evt); private void clearActionPerformed(ActionEvent evt) str = private void commitActionPerformed(java.awt.event.Act
20、ionEvent evt) if (Integer.parseInt(jT1.getText() % 100 = 0) / 数值不能是字符, 必须是100的倍数 int a = Integer.parseInt(jT1.getText(); if (a 0) JOptionPane.showMessageDialog(null, 存款不能为负数, 出错, 1); else myAccount.reccount(a); int result = javax.swing.JOptionPane.showConfirmDialog(null, 是否显示余额?, javax.swing.JOption
21、Pane.YES_NO_OPTION, javax.swing.JOptionPane.QUESTION_MESSAGE); if (result = javax.swing.JOptionPane.YES_OPTION) str = jT1.setText(str); new Display(myAccount); this.setVisible(false); else new MainFrame(); else JOptionPane.showMessageDialog(null,存款金额必须为100的整数倍! + n请确认你的金额出错提示 jT1.setText( import java.awt.event.Ac
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1