您好,欢迎访问三七文档
当前位置:首页 > 建筑/环境 > 设计及方案 > java图像界面ATM模拟程序
packagehxf;/*创建主程序*/importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.swing.GroupLayout;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.WindowConstants;classMainFrameextendsJFrame{publicJButtonchecked;publicJButtoncunkuan;publicJButtonquit;publicJButtonqukuan;publicJButtonreset;publicMainFrame(){//initComponents();//this.setLocationRelativeTo(null);initComponents();//初始化窗口this.setLocationRelativeTo(null);//让窗口处于居中位置this.setVisible(true);//使窗口显示出来//this.setVisible(false);}/*控件初始化*/privatevoidinitComponents(){cunkuan=newJButton();qukuan=newJButton();checked=newJButton();reset=newJButton();quit=newJButton();setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);setTitle(ATM柜员模拟程序);setName(mianframe);setResizable(false);cunkuan.setText(存款);cunkuan.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEventevt){cunkuanActionPerformed(evt);}});qukuan.setText(取款);qukuan.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEventevt){qukuanActionPerformed(evt);}});checked.setText(查询);checked.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEventevt){checkedActionPerformed(evt);}});reset.setText(修改密码);reset.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEventevt){resetActionPerformed(evt);}});quit.setText(退出);quit.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEventevt){quitActionPerformed(evt);}});GroupLayoutlayout=newGroupLayout(getContentPane());//GroupLayout它将组件按层次分组,以决定它们在Container中的位置getContentPane().setLayout(layout);layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().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.GroupLayout.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.swing.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.GroupLayout.Alignment.BASELINE).addComponent(quit).addComponent(qukuan)).addGap(57,57,57).addComponent(checked).addGap(39,39,39)));pack();}privatevoidquitActionPerformed(ActionEventevt){LoginFrameload=newLoginFrame();load.setVisible(true);this.setVisible(false);}privatevoidresetActionPerformed(ActionEventevt){Setpwsetpw=newSetpw(null);setpw.setVisible(true);this.setVisible(false);}privatevoidcheckedActionPerformed(ActionEventevt){Displaydis=newDisplay(null);dis.setVisible(true);this.setVisible(false);}privatevoidqukuanActionPerformed(ActionEventevt){Taketake=newTake(null);take.setVisible(true);this.setVisible(false);}privatevoidcunkuanActionPerformed(ActionEventevt){Inputinput=newInput(null);input.setVisible(true);this.setVisible(false);}}/*创建账户*/publicclassAccount{privateintcount=10000;//初始账户余额10000privateStringaccount=1;//初始账号privateStringpassword=1;//初始密码publicAccount(){}publicvoidsetpw(Stringpassword){this.password=password;}publicvoiddeccount(intmoney){count-=money;//取钱}publicvoidreccount(intmoney){count+=money;//存钱}publicintget(){returncount;}publicStringgetaccount(){//账号returnaccount;}publicStringgetpw(){returnpassword;}}packagehxf;importjava.awt.BorderLayout;importjava.awt.GridLayout;importjava.awt.event.ActionEvent;importjavax.swing.ImageIcon;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JPanel;importjavax.swing.JTextField;importjavax.swing.WindowConstants;/*显示余额界面*/publicclassDisplayextendsJFrame{publicJButtonback;privateJLabeljL1;publicJTextFieldjT1;publicJButtonquit;publicJButtonqukuan;AccountmyAccount;//这个是便以传数值的publicDisplay(Accountmyaccount){this.myAccount=myaccount;initComponents();//初始化窗口,就是把窗口画出来jT1.setText(String.valueOf(myaccount.get()));//获得用户为标题this.setLocationRelativeTo(null);this.setVisible(true);}publicvoidset(Stringstr){jT1.setText(str);}privatevoidinitComponents(){jL1=newJLabel();jT1=newJTextField(15);quit=newJButton();back=newJButton();back.setIcon(newImageIcon(xiaofangImage/back.png));qukuan=newJButton();qukuan.setIcon(newImageIcon(xiaofangImage/qukuan.png));setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);jL1.setText(您的余额为:);jL1.setIcon(newImageIcon(xiaofangImage/money.png));jT1.setEditable(false);quit.setText(退出);quit.setIcon(newImageIcon(xiaofangImage/exit.png));JPanelp1=newJPanel();p1.add(jL1);p1.add(jT1);JPanelp2=newJPanel();JPanelp3=newJPanel();JPanelp4=newJPanel();JPanelp5=newJPanel();p3.
本文标题:java图像界面ATM模拟程序
链接地址:https://www.777doc.com/doc-4962829 .html