窗口的切换
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Myfram implements ActionListener {
JFrame f1,f2;
JButton b1,b2;
JPanel p;
JLabel l1,l2;
JTextField t1,t2;
public Myfram() {
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(400, 400);
f1.setSize(300, 300);
f1.setVisible(true);
}
public static void main(String[] args) {
new Myfram();
}
class b1buton implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("请先注册!");
}
}
class b2buton implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
f1.setVisible(false);
f2=new JFrame("注册界面");
l1=new JLabel("账号:");
t1=new JTextField(20);
l2=new JLabel("密码");
t2=new JTextField(20);
p=new JPanel();
p.setBackground(Color.blue);
p.add(l1);
p.add(t1);
p.add(l2);
p.add(t2);
f2.add(p);
f2.setLocation(400, 400);
f2.setSize(300, 300);
f2.setVisible(true);
}
}
}