package cn.bank.UI;
import java.awt.Graphics;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import cn.bank.action.CheckBalance;
import cn.bank.action.UpdateBalance;
import cn.bank.domin.CardInfo;
public class WithdrawingMoneyUI extends JFrame {
/**
* 取款界面
*/
// private JLabel srje;//输入金额
private JButton je1;
private JButton je2;
private JButton je3;
private JButton je4;
private JButton je5;
private JButton qt;
private JButton fh;
private JButton qx;
private JPanel panel;
ImageIcon icon; // ImageIcon创建一个未初始化的图像图标。
// Image image;
String cardID;
public WithdrawingMoneyUI(String ss) {
super("取款");
// setLayout(null);
cardID = ss;
icon = new ImageIcon("pics/a18.jpg");
panel = new JPanel() {
protected void paintComponent(Graphics g) {
g.drawImage(icon.getImage(), 0, 0, null);
super.paintComponent(g);
}
};
panel.setOpaque(false);
getContentPane().add(panel);
panel.setLayout(null);
// srje=new JLabel("请选择你需要提取的金额:(单次最高金额为5000元)");
// srje.setBounds(150, 0, 500, 100);
je1 = new JButton("100");
je1.setBounds(80, 150, 130, 40);
je1.addActionListener(new Kuanx());
je2 = new JButton("200");
je2.setBounds(380, 150, 130, 40);
je2.addActionListener(new Kuanx());
je3 = new JButton("300");
je3.addActionListener(new Kuanx());
je3.setBounds(80, 215, 130, 40);
je4 = new JButton("500");
je4.setBounds(380, 215, 130, 40);
je4.addActionListener(new Kuanx());
je5 = new JButton("1000");
je5.setBounds(80, 280, 130, 40);
je5.addActionListener(new Kuanx());
qt = new JButton("其他面额");
qt.setBounds(380, 280, 130, 40);
qt.addActionListener(new Kuanx());
fh = new JButton("返回");
fh.setBounds(80, 345, 130, 40);
fh.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
ServiceUI ds = new ServiceUI(cardID);
ds.setVisible(true);// 返回服务选项
setVisible(false);
}
});
qx = new JButton("取消");
qx.setBounds(380, 345, 130, 40);
qx.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
System.exit(0); // 退出登陆
}
});
// panel.add(srje);
panel.add(je1);
panel.add(je2);
panel.add(je3);
panel.add(je4);
panel.add(je5);
panel.add(qt);
panel.add(fh);
panel.add(qx);
this.getContentPane().add(panel);
int Width = 585;
int Height = 469;
int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; // 获取屏幕宽和高
// 如果窗口大小超过屏幕大小,让窗口与屏幕等大
if (Height > screenHeight)
Height = screenHeight;
if (Width > screenWidth)
Width = screenWidth;
setBounds((screenWidth - Width) / 2, (screenHeight - Height) / 2,Width, Height);// 显示在屏幕正中央
setTitle("取款界面");
setResizable(false); // 将最大化按钮设置为不可用
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
class Kuanx implements ActionListener {
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
CardInfo card = new CardInfo();
CheckBalance checkBalance = new CheckBalance();
double bal = checkBalance.balance(cardID);
card.setBalance(bal);
UpdateBalance updateBalance = new UpdateBalance();
if (cmd.equals("100")) {
if (bal > 100.0) {
card.setBalance(card.getBalance() - 100.0);
updateBalance.updateAccount(card, cardID);// 传递参数到余额更新界面
new SuccessWithdrawingMoneyUI(cardID);
} else
System.out.print("您的余额不足");
}
if (cmd.equals("200")) {
if (card.getBalance() > 200.0) {
card.setBalance(card.getBalance() - 200.0);
updateBalance.updateAccount(card, cardID);// 传递参数到余额更新界面
new SuccessWithdrawingMoneyUI(cardID);
} else
System.out.print("您的余额不足");
}
if (cmd.equals("300")) {
if (card.getBalance() > 300.0) {
card.setBalance(card.getBalance() - 300.0);
updateBalance.updateAccount(card, cardID);// 传递参数到余额更新界面
new SuccessWithdrawingMoneyUI(cardID);
} else
System.out.print("您的余额不足");
}
if (cmd.equals("500")) {
if (card.getBalance() > 500.0) {
card.setBalance(card.getBalance() - 500.0);
updateBalance.updateAccount(card, cardID);// 传递参数到余额更新界面
new SuccessWithdrawingMoneyUI(cardID);
} else
System.out.print("您的余额不足");
}
if (cmd.equals("1000")) {
if (card.getBalance() > 1000.0) {
card.setBalance(card.getBalance() - 1000.0);
updateBalance.updateAccount(card, cardID);// 传递参数到余额更新界面
new SuccessWithdrawingMoneyUI(cardID);
} else
System.out.print("您的余额不足");
}
if (cmd.equals("其他面额")) {
WithdrawingMoneyUI4OtherFiguer cc = new WithdrawingMoneyUI4OtherFiguer(cardID);
cc.setVisible(true);
setVisible(false);
}
}
}
}
- 1
- 2
前往页