📄 mainframe.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MainFrame extends JFrame implements ActionListener{
JButton button1, button2, button3;
JLabel Label0, Label1 , Label2 , Label3 ,Label4,Label5;
Bank b1 = new Bank();
public Image image;
public MainFrame()
{
//设置窗口标题
super("ATM取款机");
//设置布局方式
setLayout(new GridBagLayout());
Label0 = new JLabel(" ");
Label5 = new JLabel(" ");
button1 = new JButton(" 注册 ");
Label1 = new JLabel(" 注册成为ATM用户");
button2 = new JButton(" 登录 ");
Label2 = new JLabel(" ATM用户登录");
button3 = new JButton(" 取消 ");
Label3 = new JLabel(" 退出系统");
Label4 = new JLabel();
ImageIcon img = new ImageIcon( "bj01.jpg ");
Label4.setIcon(img);
getLayeredPane().add(Label4, new Integer(Integer.MIN_VALUE));
Label4.setBounds(0,0,img.getIconWidth(), img.getIconHeight());
((JPanel)getContentPane()).setOpaque(false);
// 设置布局都是在这里实现的。。。。
add(Label5 , new GBC(0, 1).setWeight(100, 100).setInsets(2));
add(Label0 , new GBC(1, 1).setWeight(100, 100).setInsets(2)); //把Label0 放在 0列0行, 它占用了2列1行的单元格,默认把Label0放在单元中间
add(button1, new GBC(1, 2).setInsets(2)); //把button1 放到0列1行, 并且放在东边, 外部增加10px空间
add(Label1 , new GBC(2, 2).setWeight(100, 100).setInsets(2)); // 把Label1 放到1列1行, 如果水平,垂直方向有多余空间的话。按比例给YesBtn 加空间, 外部增加10px空间
add(button2 , new GBC(1, 3).setInsets(2)); //把button2 放到0列2行, 并且放在东边, 外部增加10px空间
add(Label2 , new GBC(2, 3).setWeight(100, 100).setInsets(2)); // 把Label2 放到1列2行, 如果水平,垂直方向有多余空间的话。按比例给YesBtn 加空间, 外部增加10px空间
add(button3, new GBC(1, 4).setInsets(2)); //把button3 放到0列3行, 并且放在东边, 外部增加10px空间
add(Label3, new GBC(2, 4).setWeight(100, 100).setInsets(2)); // 把Label3 放到1列3行, 如果水平,垂直方向有多余空间的话。按比例给YesBtn 加空间, 外部增加10px空间
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
setSize(400,384);
setLocation(250,250);
}
public void actionPerformed(ActionEvent e) {
// TODO 自动生成方法存根
if(e.getSource()== button1)
{
LoginFrame login = new LoginFrame(this,b1);
login.setVisible(true);
this.setVisible(false);
}
else if(e.getSource()== button2)
{
LoginoldFrame login = new LoginoldFrame(this,b1);
login.setVisible(true);
this.setVisible(false);
}
else if(e.getSource()== button3)
{
JOptionPane.showMessageDialog(null,"谢谢使用ATM系统");
System.exit(0);
}
}
public static void main(String args[])
{
MainFrame Frame=new MainFrame();
Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Frame.setVisible(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -