代码改变世界

窗口创建

2019-05-15 23:23  ~何处不相逢~  阅读(168)  评论(0编辑  收藏  举报

package 窗口;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class ck {
public static class work implements ActionListener {
JFrame f;
JPanel p,p1;
JButton b,b1;
JLabel l,l1,l2;
JTextField t;
JPasswordField s;
public work() {
f = new JFrame("QQ");
p = new JPanel();
p1 = new JPanel();
b = new JButton("注册:");
b1 = new JButton("登录:");
b1.setForeground(Color.GREEN);
t = new JTextField();
s = new JPasswordField();
t.setBounds(110,82,200,28);
s.setBounds(110,140,200,28);
p.setLayout( null );
p1.setLayout(null);
b.setBounds(90, 210, 80, 25);
b1.setBounds(240, 210, 80, 25);
b.addActionListener(this);
b1.addActionListener(this);
l = new JLabel("账号:");
l1 = new JLabel("密码:");
l2 = new JLabel("登录成功!");
l2.setBounds(130, 15, 150, 60);
l.setBounds(75, 80, 80, 30);
l1.setBounds(75, 140, 80, 30);
p.add(b);
p.add(b1);
p.add(l);
p.add(l1);
p.add(t);
p.add(s);
p.setBackground(new Color(240,248,255));
p1.add(l2);
f.add(p);
f.setLocation(430,198);
f.setVisible(true);
f.setSize(435, 324);
b1.setFont(new Font("仿宋", Font.BOLD, 13));
b.setFont(new Font("仿宋", Font.BOLD, 13));
}
public static void main(String args[]) {
new work();
}

public void actionPerformed(ActionEvent e) {
f.setVisible(false);
JFrame f1 = new JFrame("QQ");
f1.setVisible(true);
f1.add(p1);
p1.add(l2);
f1.setLocation(430,198);
f1.setSize(450,180);
p1.setBackground(new Color(230,230,250));
}
}
}