JAVA 弱智ATM

來源:互聯網
上載者:User

標籤:小作品   java   atm   

閑來無事,敲著玩玩。



代碼:

package ATM;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class ATM extends JFrame implements ActionListener { private JPanel pan; private JPanel sec; private JButton log; static JLabel text1=new JLabel("帳號"); static JLabel text2=new JLabel("密碼"); static JLabel text3=new JLabel("存款"); static JLabel text4=new JLabel("取款"); static JLabel text5=new JLabel("餘額"); static JTextField account=new JTextField("",18); static JTextField password=new JTextField("",18); static JTextField savein=new JTextField("",12); static JButton saveb=new JButton("確認"); static JTextField takeout=new JTextField("",12); static JButton takeb=new JButton("確認"); static JTextField left=new JTextField("",12); static int money=10000; String zero=Integer.toString(0); String acc=new String("888888"); String pas=new String("888888"); ATM(){  this.setBounds(400, 300, 260, 200);  pan = new JPanel();  log = new JButton("登入");  log.addActionListener(this);  this.add(pan);  this.setAlwaysOnTop(true);  this.setVisible(true);  pan.add(text1);  pan.add(account);  pan.add(text2);  pan.add(password);  pan.add(log);  this.setTitle("ATM");} public static void main(String args[]) {  new ATM(); } public void actionPerformed(ActionEvent e)  {  if(e.getSource()==log)  {String ac=account.getText();String pa=password.getText();if(ac.equals(acc)&&pa.equals(pas))    {this.setVisible(false);        new Another();    }  } }class Another extends JFrame{     Another()     {    sec = new JPanel();    this.add(sec);        this.setTitle("ATM");        this.setBounds(400, 300, 260, 200);        this.setVisible(true);        sec.add(text3);        sec.add(savein);        sec.add(saveb);        sec.add(text4);        sec.add(takeout);        sec.add(takeb);        sec.add(text5);        sec.add(left);        String M=Integer.toString(money);left.setText(M);left.setEditable(false);savein.setText(zero);takeout.setText(zero);        saveb.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){String tmp=savein.getText();int val=Integer.parseInt(tmp);savein.setText(zero);takeout.setText(zero);if(val>0){money+=val;String M=Integer.toString(money);left.setText(M);left.setEditable(false);JOptionPane.showMessageDialog(null,"存款成功!"); }else{JOptionPane.showMessageDialog(null,"你逗我呢吧!"); }}});        takeb.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){String tmp=takeout.getText();int val=Integer.parseInt(tmp);savein.setText(zero);takeout.setText(zero);if(val>=0 && val<=money && val%100==0){money-=val;String M=Integer.toString(money);left.setText(M);left.setEditable(false);JOptionPane.showMessageDialog(null,"取款成功!");  }else{JOptionPane.showMessageDialog(null,"非法操作!"); }}});     }}}


JAVA 弱智ATM

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.