课外作业----窗口切换

package guweiyi;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
    
    public class MyFrame implements ActionListener{
        JFrame f1,f2;
        JPanel p1,p2;
        JLabel l1;
        JLabel l2;
        JButton b1,b2;
        JTextField t1;
        JTextField t2;
        Container c;
        JPasswordField s;
    public MyFrame(){
        f1=new JFrame("登陆窗口");
        p1=new JPanel();
        c = new Container();
        l1=new JLabel("账号:");
        l2=new JLabel("密码:");
        t1=new JTextField(10);
        t2=new JTextField(10);
        b1=new JButton("登陆");
        b1.addActionListener((ActionListener) this);
        b2= new JButton("注册");
        t1 = new JTextField(10);
        s = new JPasswordField(10);
        f1.add(p1);
        p1.add(l1);
        p1.add(t1);
        p1.add(l2);
        p1.add(t2);
        p1.add(b1);
        p1.add(b2);
        p1.add(s);
       
        f1.setLocation(500,300);
        f1.setSize(400, 250);
        f1.setVisible(true);
        p1.setBackground(Color.pink);
    }
        public static void main(String[] args){
            new MyFrame();
        }
        public void actionPerformed(ActionEvent arg0) {
            p2 = new JPanel();
            f2 = new JFrame("登陆成功");
            f2.setSize(400, 200);
            f2.setVisible(true);
            f2.add(p2);
            f1.setVisible(false);
    }
    }

 

 

课外作业----窗口切换_第1张图片课外作业----窗口切换_第2张图片

转载于:https://www.cnblogs.com/zhangyixing/p/10887788.html

你可能感兴趣的:(java)