1、運用事件處理相關知識,完成兩個窗口之間的切換,例如:登陸窗口------》注冊窗口
package
?Date;
import
?java.awt.Color;
import
?java.awt.Font;
import
?java.awt.event.ActionEvent;
import
?java.awt.event.ActionListener;
import
?javax.swing.*;
public
?class
?myframe?
implements
?ActionListener {
???
JFrame f1,f2;
???
JPanel p1,p2;
???
JButton b1,b2;
???
JLabel l1,l2,l3;
???
JTextField t1,t2;
//文本框
???
public
?myframe() {
???????
f1=
new
?JFrame(
"LYX"
);
???????
f2=
new
?JFrame(
"LYX"
);
???????
p1=
new
?JPanel();
???????
p2=
new
?JPanel();
???????
p1.setLayout(
null
);
//流布局
???????
p2.setLayout(
null
);
???????
b1=
new
?JButton(
"注冊"
);
???????
b2=
new
?JButton(
"登錄"
);
???????
l1=
new
?JLabel(
"賬戶"
);
???????
l1.setFont(
new
?Font(
"楷體"
,Font.BOLD,
18
));
//自定義標簽字體
???????
l2=
new
?JLabel(
"密碼"
);
???????
l2.setFont(
new
?Font(
"楷體"
,Font.BOLD,
18
));
???????
l3=
new
?JLabel(
"登錄成功!"
);
???????
l3.setForeground(Color.red);
???????
t1=
new
?JTextField();
???????
t2=
new
?JTextField();
???????
b1.addActionListener(
this
);
???????
b2.addActionListener(
this
);
???????
f1.add(p1);
???????
p1.add(b1);
???????
p1.add(b2);
???????
p1.add(l1);
???????
p1.add(l2);
???????
p1.add(t1);
???????
p1.add(t2);
???????
b1.setBounds(
150
,
150
,
60
,
40
);
???????
b2.setBounds(
270
,
150
,
60
,
40
);
???????
l1.setBounds(
80
,
50
,
40
,
30
);
???????
l2.setBounds(
80
,
100
,
40
,
30
);
???????
t1.setBounds(
120
,
50
,
300
,
30
);
???????
t2.setBounds(
120
,
100
,
300
,
30
);
???????
f1.setVisible(
true
);
???????
f1.setSize(
500
,
300
);
???
}
????
public
?static
?void
?main(String[] args) {
?????????
new
?myframe();
}
????
public
?void
?actionPerformed(ActionEvent e) {
????????
f1.setVisible(
false
);
????????
p2.setBackground(
new
?Color(
211
,
252
,
4
));
//自定義面板顏色
????????
f2.setVisible(
true
);
????????
f2.add(p2);
????????
p2.add(l3);
????????
l3.setBounds(
225
,
75
,
150
,
60
);
????????
f2.setLocation(
600
,
0
);
????????
f2.setSize(
500
,
300
);
????
}
}