當前位置:編程學習大全網 - 編程語言 - java swing 做壹個簡單的模擬取款機的程序

java swing 做壹個簡單的模擬取款機的程序

import java.awt.FlowLayout;

import java.awt.GridLayout;

import java.awt.TextArea;

import java.awt.TextField;

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.JPanel;

public class VirtualATM {

JPanel jpt,jp1,jp2;

JFrame jf;

JLabel lb1;

JButton b1,b2,b3,b4,b5,b6;

TextField tf;

TextArea ta;

public void launchFrame() {

jf = new JFrame();

jf.setTitle("模擬自動取款機");

jf.setBounds(300, 300, 400, 400);

tf = new TextField();

ta = new TextArea("歡迎使用本取款系統,請在上方輸入您的賬號密碼。");

jpt = new JPanel(new GridLayout(2,1));

jpt.add(tf);

jpt.add(ta);

/* lb1 = new JLabel("歡迎使用本取款機!");

*/ b1 = new JButton("退出");

b2 = new JButton("確定");

b1.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

System.exit(0);

}

});

b2.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

if(tf.getText().equals("123456")){

jp1.setVisible(false);

jp2.setVisible(true);

ta.setText("用戶登錄系統成功,請開始操作!");

tf.setText("");

}

else{

ta.setText("您輸入的密碼有誤,請重新輸入!");

}

}

});

b3 = new JButton("退出");

b3.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

System.exit(0);

}

});

b4 = new JButton("存款");

b5 = new JButton("取款");

b6 = new JButton("余額查詢");

jp1 = new JPanel(new FlowLayout());

/* jp1.add(lb1);

*/ jp1.add(b2);

jp1.add(b3);

jp2 = new JPanel(new GridLayout(2,2));

jp2.add(b4);

jp2.add(b5);

jp2.add(b6);

jp2.add(b1);

jp2.setVisible(false);

jf.setLayout(new GridLayout(3,1));

jf.add(jpt);

jf.add(jp1);

jf.add(jp2);

jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

jf.setVisible(true);

}

public static void main(String[] args) {

VirtualATM va = new VirtualATM();

va.launchFrame();

}

}

只寫了個雛形,密碼123456,妳可以自己改下,有時間我再幫妳改.

  • 上一篇:如何在網絡上構建虛擬現實
  • 下一篇:WINDOWS程序設計的特點是什麽?
  • copyright 2024編程學習大全網