代码改变世界

窗口的切换

2019-06-05 15:17  飘转至原点  阅读(200)  评论(0编辑  收藏  举报
package LHB.inherit;

 import java.awt.GridLayout;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
  import javax.swing.*;
 public class Windows2 {
     JFrame jf;
     JButton jb1;
     JButton jb2;
     JPanel jp;
     JLabel jl;
     public Windows2() 
    {
         jf = new JFrame();
         jb1 = new JButton("注册");
        jb2 = new JButton("登录");
         jp = new JPanel();
         jl = new JLabel("请选择您需要进行的操作");
         jb1.addActionListener(new ActionListener() {
             @Override
             public void actionPerformed(ActionEvent e) {
                 JFrame jf1 = new JFrame();
                 JPanel jp1 = new JPanel();
                 JLabel jl1 = new JLabel("请输入您的个人信息");
                 JTextArea jta1 = new JTextArea(3,10);
                 jf.setVisible(false);
                 jta1.setLineWrap(true);
                 jp1.add(jl1);
                 jp1.add(jta1);
                 jf1.add(jp1);
                 jf1.setSize(600,200);
                 jf1.setLocation(800, 400);
                 jf1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                 jf1.setVisible(true);
             }
         });
         jb2.addActionListener(new ActionListener() {
             @Override
            public void actionPerformed(ActionEvent e) {
                JFrame jf1 = new JFrame();
                 JPanel jp1 = new JPanel();
                 JLabel jl1 = new JLabel("登陆成功");
                 jf.setVisible(false);
                 jp1.add(jl1);
                 jf1.add(jp1);
                 jf1.setSize(200,100);
                 jf1.setLocation(800, 400);
                 jf1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                 jf1.setVisible(true);
             }
         });
         jp.add(jl);
         jp.add(jb1); 
         jp.add(jb2);
         jf.add(jp);
         jf.setSize(300,100);
         jf.setLocation(800, 400);
         jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         jf.setVisible(true);
     }
     public static void main(String[] args) {
         new Windows2();
 
     }


 }