窗口的切换

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

import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

public class 窗口 implements ActionListener {
 JPanel p1,p2;
 JFrame f1,f2;
 JButton b1,b2;
 JLabel l1,l2;
 JTextField t1,t2;
 Container c;
 JPasswordField s;
public 窗口(){
  p1 = new JPanel();
  f1 = new JFrame();
  c = new Container();
  
 
  l1 = new JLabel("用户名:");
  l2 = new JLabel("密码:");
  
  b1= new JButton("登录");
  b1.addActionListener(this);
 
  b2= new JButton("注册");
  
   t1 = new JTextField(10);
   s = new JPasswordField(10);
   f1.setSize(400, 200);
   f1.setVisible(true);
   f1.add(p1);
   p1.add(l1);
   p1.add(t1);
   p1.add(l2);
   p1.add(s);
   p1.add(b1);
   p1.add(b2);
 
}
public static void main(String[]args){ 
      new  窗口();
}
public void actionPerformed(ActionEvent arg0) {
 p2 = new JPanel();
 f2 = new JFrame("登陆成功");
 f2.setSize(400, 200);
 f2.setVisible(true);
 f2.add(p2);
 f1.setVisible(false);
  
}
}

 

posted @ 2019-05-17 23:22  本山叔叔  阅读(150)  评论(0编辑  收藏  举报