import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.filechooser.*;
import java.io.*;
class MY extends JFrame implements ActionListener{
JLabel jL1,jL2,jL3;
JButton jB1,jB2;
JTextField jF1;
JPasswordField jP1;
public MY()
{
super("密码界面");
jL1=new JLabel ("用户名称");
jL1.setForeground(Color.blue);
jL1.setFont(new Font("楷体",Font.BOLD,12));
jL1.setBounds(15,5,60,20);
jL2=new JLabel ("密码");
jL2.setForeground(Color.blue);
jL2.setFont(new Font("楷体",Font.BOLD,12));
jL2.setBounds(15,25,60,20);
jF1=new JTextField("",20);
jF1.setBounds(110,5,100,20);
jP1=new JPasswordField("",20);
jP1.setBounds(110,25,100,20);
jB1=new JButton("确定");
jB1.setBounds(80,70,60,30);
jB1.addActionListener(this);
jB2=new JButton("退出");
jB2.setBounds(130,50,60,30);
jB2.addActionListener(this);
jL3=new JLabel("");
jL3.setBounds(60,90,200,30);
Container winContainer=this.getContentPane();
winContainer.setLayout(null);
winContainer.add(jL1);
winContainer.add(jL2);
winContainer.add(jL3);
winContainer.add(jB1);
winContainer.add(jB1);
winContainer.add(jP1);
winContainer.add(jF1);
this.setSize(250,150);
this.setVisible(true);
}
public static void main(String[] args)
{
MY w1=new MY();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==jB1)
{
if(jF1.getText().equals("JAVA")&&jP1.getText().equals("1234"))
{
MybetExample P1=new MybetExample("ATM机");
}
else
jL3.setText("密码错误");
}
else if(e.getSource()==jB2)
{
System.exit(0);
}
}
}
class MybetExample extends JFrame implements ActionListener
{
JMenuItem CKMenuItem,QKMenuItem,aboutMenuItem,exitMenuItem,mima;
JMenu fileMenu,systemMenu;
JMenuBar mbar;
JLabel jL1,jL2;
JTextField jT1,jT2;
boolean flag=false;
Container winContainer;
static int YUER=1000;
static int JINER=0;
public MybetExample(String title)
{
super(title);
CKMenuItem=new JMenuItem("存款");
CKMenuItem.addActionListener(this);
QKMenuItem=new JMenuItem("取款");
QKMenuItem.addActionListener(this);
mima=new JMenuItem("修改密码");
mima.addActionListener(this);
aboutMenuItem=new JMenuItem("关于");
aboutMenuItem.addActionListener(this);
exitMenuItem=new JMenuItem("退出");
exitMenuItem.addActionListener(this);
fileMenu=new JMenu("ATM操作");
systemMenu=new JMenu("系统");
mbar=new JMenuBar();
fileMenu.add(CKMenuItem);
fileMenu.add(QKMenuItem);
fileMenu.add(mima);
systemMenu.add(aboutMenuItem);
systemMenu.addSeparator();
systemMenu.add(exitMenuItem);
mbar.add(fileMenu);
mbar.add(systemMenu);
this.setJMenuBar(mbar);
jL1=new JLabel("卡号");
jL1.setForeground(Color.blue);
jL1.setBounds(50,100,50,30);
jL2=new JLabel("余额");
jL2.setForeground(Color.blue);
jL2.setBounds(50,150,50,30);
jT1=new JTextField("JAVA");
jT1.setBounds(150,100,80,30);
jT1.setEditable(false);
jT1.addActionListener(this);
jT2=new JTextField(YUER+"");
jT2.setBounds(150,150,80,30);
jT2.setEditable(false);
jT2.addActionListener(this);
winContainer=this.getContentPane();
winContainer.setLayout(null);
winContainer.add(jL1);
winContainer.add(jL2);
winContainer.add(jT1);
winContainer.add(jT2);
this.setSize(400,400);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==CKMenuItem)
{
CunKuan P1=new CunKuan();
P1.setBounds(0,0,340,250);
winContainer.removeAll();
winContainer.add(P1);
winContainer.repaint();
}
else if(e.getSource()==QKMenuItem)
{
QuKuan P1=new QuKuan();
P1.setBounds(0,0,340,250);
winContainer.removeAll();
winContainer.add(P1);
winContainer.repaint();
}
else if(e.getSource()==mima)
{
Genggai P1=new Genggai();
P1.setBounds(0,0,340,250);
winContainer.removeAll();
winContainer.add(P1);
winContainer.repaint();
}
else if(e.getSource()==aboutMenuItem)
{
winContainer.removeAll();
jL1.setText("蜡笔小新银行");
jL1.setFont(new Font("宋体",Font.BOLD,32));
jL1.setBounds(60,35,300,100);
winContainer.add(jL1);
winContainer.repaint();
}
if(e.getSource()==exitMenuItem)
{
System.exit(0);
}
}
}
class CunKuan extends JPanel implements ActionListener
{
int YUER,JINER;
JLabel jL1,jL2;
JTextField jT1,jT2;
JButton jB1,jB2;
public CunKuan()
{
this.YUER=MybetExample.YUER;
this.JINER=MybetExample.JINER;
this.setLayout(null);
ChuangKou();
}
void ChuangKou()
{
jL1=new JLabel("卡号");
jL1.setForeground(Color.blue);
jL1.setBounds(50,100,50,30);
jL2=new JLabel("存款");
jL2.setForeground(Color.blue);
jL2.setBounds(50,150,50,30);
jT1=new JTextField("JAVA");
jT1.setBounds(150,100,80,30);
jT1.setEditable(false);
jT1.addActionListener(this);
jT2=new JTextField("");
jT2.setBounds(150,150,80,30);
jT1.setEditable(true);
jT2.addActionListener(this);
jB1=new JButton("确定");
jB1.setBounds(60,200,80,30);
jB1.addActionListener(this);
jB2=new JButton("恢复");
jB2.setBounds(160,200,80,30);
jB2.addActionListener(this);
this.add(jL1);
this.add(jL2);
this.add(jT1);
this.add(jT2);
this.add(jB1);
this.add(jB2);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==jB1)
{
JINER=Integer.parseInt(jT2.getText());
if(JINER<0)
{
JOptionPane.showMessageDialog(this,"存款金额不能小于0","信息提示",2);
}
else
{
MybetExample.YUER=YUER+JINER;
showSuccess();
}
}
else
{
jT1.setText("JAVA");
jT2.setText("");
}
}
public void showSuccess()
{
JLabel jshow1=new JLabel("存款成功。");
JLabel jshow2=new JLabel("存款金额:"+JINER);
JLabel jshow3=new JLabel("当前余额:"+MybetExample.YUER);
jshow1.setFont(new Font("宋体",Font.BOLD,18));
jshow2.setFont(new Font("宋体",Font.BOLD,18));
jshow3.setFont(new Font("宋体",Font.BOLD,18));
jshow1.setForeground(Color.RED);
jshow2.setForeground(Color.RED);
jshow3.setForeground(Color.RED);
jshow1.setBounds(40,5,300,100);
jshow2.setBounds(40,35,300,100);
jshow3.setBounds(40,65,300,100);
this.removeAll();
this.add(jshow1);
this.add(jshow2);
this.add(jshow3);
this.repaint();
}
}
class QuKuan extends JPanel implements ActionListener
{
int YUER,JINER;
JLabel jL1,jL2;
JTextField jT1,jT2;
JButton jB1,jB2;
public QuKuan()
{
this.YUER=MybetExample.YUER;
this.JINER=MybetExample.JINER;
this.setLayout(null);
ChuangKou();
}
void ChuangKou()
{
jL1=new JLabel("卡号");
jL1.setForeground(Color.blue);
jL1.setBounds(50,100,50,30);
jL2=new JLabel("取款");
jL2.setForeground(Color.blue);
jL2.setBounds(50,150,50,30);
jT1=new JTextField("JAVA");
jT1.setBounds(150,100,80,30);
jT1.setEditable(false);
jT1.addActionListener(this);
jT2=new JTextField("");
jT2.setBounds(150,150,80,30);
jT1.setEditable(true);
jT2.addActionListener(this);
jB1=new JButton("确定");
jB1.setBounds(60,200,80,30);
jB1.addActionListener(this);
jB2=new JButton("恢复");
jB2.setBounds(160,200,80,30);
jB2.addActionListener(this);
this.add(jL1);
this.add(jL2);
this.add(jT1);
this.add(jT2);
this.add(jB1);
this.add(jB2);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==jB1)
{
JINER=Integer.parseInt(jT2.getText());
if(JINER>5000)
{
JOptionPane.showMessageDialog(this,"存款金额不能超过5000元","信息提示"