- import javax.swing.*;
- import java.awt.event.*;
- public class TestBank {
- public static void main(String args[]) {
- new MyFrame().frame();
- }
- }
- class MyListener implements ActionListener {
- public void actionPerformed(ActionEvent e) {
- System.out.print(e.getSource());
- System.out.print("btShowMoney clicked");
- }
- }
- class MyFrame extends JFrame {
- void frame() {
- Object[] possibleValues = { "用户1", "用户2" };
- Object selectedValue = JOptionPane.showInputDialog(null, "Choose one",
- "Input", JOptionPane.INFORMATION_MESSAGE, null, possibleValues,
- possibleValues[0]);
- // System.out.println();
- JFrame frame = new JFrame(selectedValue.toString() + "正在操作");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setBounds(300, 300, 300, 300);
- // frame.setLayout(new FlowLayout());
- JButton btGetMoney = new JButton("取款");
- btGetMoney.addActionListener(new MyListener());
- JButton btSaveMoney = new JButton("存款");
- btSaveMoney.addActionListener(new MyListener());
- JButton btShowMoney = new JButton("显示余额");
- btShowMoney.addActionListener(new MyListener());
- JButton btShowName = new JButton("显示帐号");
- btShowName.addActionListener(new MyListener());
- frame.add(btGetMoney);
- frame.add(btSaveMoney);
- frame.add(btShowMoney);
- frame.add(btShowName);
- frame.setVisible(true);
- }
- }