?? mainframe.java
字號(hào):
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()
{
//設(shè)置窗口標(biāo)題
super("ATM取款機(jī)");
//設(shè)置布局方式
setLayout(new GridBagLayout());
Label0 = new JLabel(" ");
Label5 = new JLabel(" ");
button1 = new JButton(" 注冊(cè) ");
Label1 = new JLabel(" 注冊(cè)成為ATM用戶");
button2 = new JButton(" 登錄 ");
Label2 = new JLabel(" ATM用戶登錄");
button3 = new JButton(" 取消 ");
Label3 = new JLabel(" 退出系統(tǒng)");
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);
// 設(shè)置布局都是在這里實(shí)現(xiàn)的。。。。
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行的單元格,默認(rèn)把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 自動(dòng)生成方法存根
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系統(tǒng)");
System.exit(0);
}
}
public static void main(String args[])
{
MainFrame Frame=new MainFrame();
Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Frame.setVisible(true);
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -