1 import java.awt.GridLayout;
2 import java.awt.event.ActionEvent;
3 import java.awt.event.ActionListener;
4
5 import javax.swing.JButton;
6 import javax.swing.JFrame;
7 import javax.swing.JLabel;
8 import javax.swing.JPanel;
9 import javax.swing.JTextArea;
10
11 public class WindowsSwitch {
12 JFrame jf;
13 JButton jb1;
14 JButton jb2;
15 JPanel jp;
16 JLabel jl;
17 public WindowsSwitch()
18 {
19 jf = new JFrame();
20 jb1 = new JButton("注册");
21 jb2 = new JButton("登录");
22 jp = new JPanel();
23 jl = new JLabel("欢迎使用本程序\n请选择您需要进行的操作");
24 jb1.addActionListener(new ActionListener() {
25 @Override
26 public void actionPerformed(ActionEvent e) {
27 JFrame jf1 = new JFrame();
28 JPanel jp1 = new JPanel();
29 JLabel jl1 = new JLabel("请输入您的手机号和您的个人信息");
30 JTextArea jta1 = new JTextArea(3,10);
31 jf.setVisible(false);
32 jta1.setLineWrap(true);
33 jp1.add(jl1);
34 jp1.add(jta1);
35 jf1.add(jp1);
36 jf1.setSize(600,200);
37 jf1.setLocation(800, 400);
38 jf1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
39 jf1.setVisible(true);
40 }
41 });
42 jb2.addActionListener(new ActionListener() {
43 @Override
44 public void actionPerformed(ActionEvent e) {
45 JFrame jf1 = new JFrame();
46 JPanel jp1 = new JPanel();
47 JLabel jl1 = new JLabel("登陆成功");
48 jf.setVisible(false);
49 jp1.add(jl1);
50 jf1.add(jp1);
51 jf1.setSize(200,100);
52 jf1.setLocation(800, 400);
53 jf1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
54 jf1.setVisible(true);
55 }
56 });
57 jp.add(jl);
58 jp.add(jb1);
59 jp.add(jb2);
60 jf.add(jp);
61 jf.setSize(300,100);
62 jf.setLocation(800, 400);
63 jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
64 jf.setVisible(true);
65 }
66 public static void main(String[] args) {
67 new WindowsSwitch();
68
69 }
70
71
72 }
原文:https://www.cnblogs.com/371x/p/10884062.html