// 主面板pnBasic是用来装pnDate和标签文字的 。
pnDate = new JPanel(new GridLayout(2, 2));
// pnDate面板是为了装表单的 。
pnLabel = new JPanel();
JLabel top = new JLabel("欢迎来到中国银行!");
pnLabel.add(top);
// 先将数值添加在一个容器中并设置其在容器的右边,在将容器添加在网格的第一格
JPanel jp1 = new JPanel();
JLabel number = new JLabel("数值:");
final JTextField box = new JTextField(5);
jp1.add(number);
jp1.add(box);
JPanel jp2 = new JPanel();
JButton create = new JButton("新建银行账户");
jp2.add(create);
JButton take = new JButton("取款");
JButton in = new JButton("存款");
pnDate.add(jp1);
pnDate.add(jp2);
pnDate.add(take);
pnDate.add(in);
// 加一句下面的就好了
JPanel jpS = new JPanel();
final JLabel total = new JLabel("您现在的账户余额是:0 元");
jpS.add(total);
pnBasic.setLayout(new BorderLayout());
pnBasic.add(pnLabel, BorderLayout.NORTH);
pnBasic.add(pnDate, BorderLayout.CENTER);
pnBasic.add(jpS, BorderLayout.SOUTH);
setContentPane(pnBasic);
setBounds(400, 250, 500, 500);
pack();
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setVisible(true);
pack();
in.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (box.getText() != nullbox.getText() != "") {
try {
double count = Double.parseDouble(box.getText());
if (count0) {
atm.save(count);
total.setText("您现在的账户余额是:" + atm.getMoney() + "元");
box.setText("");
}
} catch (Exception e1) {
System.out.println("您输入的数值必须是数字");
}
}
}
});
take.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (box.getText() != nullbox.getText() != "") {
try {
double count = Double.parseDouble(box.getText());
if (count = 0count = atm.getMoney()) {
atm.draw(count);
total.setText("您现在的账户余额是:" + atm.getMoney() + "元");
box.setText("");
} else {
System.out.println("你的余额不足,取款失败");
}
} catch (Exception e1) {
System.out.println("您输入的数值必须是数字");
}
}
}
});
create.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
total.setText("您现在的账户余额是:0元");
atm.setMoney(0);
box.setText("");
}
});
}
public static void main(String[] args) {
new TestATM();
}
}
JAVA模拟ATM机import java.util.*;
public class ATM {
static int people=123456;
static int mima=123456;
static int yue=10000;
static Scanner in=null;
public ATM(int people,int mima){
this.mima=mima;
}
public static void main(String[] args) {
chongxindenglu();
int count=1;
while(count!=0){
System.out.println("1、查询余额");
System.out.println("2、取款");
System.out.println("3、存款");
System.out.println("4、修改密码");
System.out.println("5、重新登录");
count=in.nextInt();
switch(count){
case 1: System.out.println(10000); System.out.println(); break;
case 2: quKuan(); break;
case 3: cunKuan(); break;
case 4: xiugai(); break;
case 5: chongxindenglu();
}
}
}
public static void quKuan(){
System.out.println("请输入取款金额:");
int qukuanjine=in.nextInt();
if(qukuanjine5000){
System.out.println("取款金额不能大于5000"+"\n");
}else{
if(qukuanjine%100!=0){
System.out.println("取款金额必须为100模拟atm机java代码的整数倍"+"\n");
推荐阅读
- 做快手直播要什么设备,做快手直播都需要什么设备
- 前端css颜色,前端 颜色
- 服务器邮箱,服务器邮箱怎么改密码
- oracle用户表空间配额,oracle设置用户表空间
- vb.net窗体图标 vb窗体图标更改
- 云监控下载,云监控下载软件
- 向日葵免费下载,向日葵下载方法
- javamongodb增删改查,java增删改查入门小项目
- linux显示文件命令 linux显示文件信息命令