import java.awt.Color;
import java.awt.event.*;
import javax.swing.*;
public class My1 implements ActionListener{
JFrame f1,f2;
JButton b;
JPanel p1,p2;
JLabel l1,l2,l3;
JTextField t1,t2;
public My1(){
f1=new JFrame();
p1=new JPanel();
b=new JButton("点击");
t1=new JTextField(10);
t2=new JTextField(10);
l1=new JLabel("账号:");
l2=new JLabel("密码:");
b.addActionListener(this);
p1.add(l1);
p1.add(t1);
p1.add(l2);
p1.add(t2);
p1.add(b);
f1.add(p1);
f1.setSize(400,300);
f1.setVisible(true);
}
public static void main(String[]args){
new My1();
}
@Override
public void actionPerformed(ActionEvent e) {
p1.setBackground(Color.pink);
f2= new JFrame();
l3 = new JLabel("该账号未注册");
f2.setBounds(600, 600,200 ,150 );
f2.setSize(400,300);
f2.setVisible(true);
p2=new JPanel();
p2.add(l3);
f2.add(p2);
p2.setBackground(Color.orange);
}
}
原文:https://www.cnblogs.com/song0216/p/10878803.html