窗口的切换

1、运用事件处理相关知识,完成两个窗口之间的切换,例如:登陆窗口------》注册窗口

package ccc;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class lgm implements ActionListener{
JFrame f1,f2;
JButton b1,b2;
JPanel p;
JLabel l1,l2;
JTextField t1,t2;
public lgm() {
f1=new JFrame("登录界面");
b1=new JButton("登录");
b1.addActionListener(new b1buton());
b2=new JButton("注册");
b2.addActionListener(new b2buton());
p=new JPanel();
p.add(b1);
p.add(b2);
f1.add(p);
f1.setLocation(100, 100);
f1.setSize(800, 700);
f1.setVisible(true);
}
public static void main(String[]arge){
new lgm();
}
class b1buton implements ActionListener{
public void actionPerformed(ActionEvent e) {
f1.setVisible(true);
f2=new JFrame("注册界面");
l1=new JLabel("账号:");
t1=new JTextField(30);
l2=new JLabel("密码");
t2=new JTextField(30);
p=new JPanel();
p.setBackground(Color.yellow);
p.add(l1);
p.add(t1);
p.add(l2);
p.add(t2);
p.add(b1);
f1.add(p);
f2.add(p);
f2.setLocation(900, 100);
f2.setSize(800, 700);
f2.setVisible(true);
}
}
class b2buton implements ActionListener{
public void actionPerformed(ActionEvent e) {
f1.setVisible(true);
f2=new JFrame("注册界面");
l1=new JLabel("账号:");
t1=new JTextField(30);
l2=new JLabel("密码");
t2=new JTextField(30);
p=new JPanel();
p.setBackground(Color.blue);
p.add(l1);
p.add(t1);
p.add(l2);
p.add(t2);
p.add(b2);
f2.add(p);
f2.setLocation(900, 100);
f2.setSize(800, 700);
f2.setVisible(true);
}
}
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub

}
}

posted @ 2019-05-16 22:36  姚中意  阅读(158)  评论(0编辑  收藏  举报