Swing组件

头大。。感觉好多东西要记住

package swing;

import java.awt.*;
import javax.swing.*;

public class SwingTest1 {
JFrame f;
JPanel p;
JLabel l;
JTextField tf;
JLabel lq;
JPasswordField we;
JTextArea ta;
JScrollPane sp;
ButtonGroup bg;
JRadioButton rb1,rb2;
public SwingTest1() {
f = new JFrame("hello");
p = new JPanel();
l = new JLabel("账号:");
l.setFont(new Font("宋体",Font.BOLD,20));
lq = new JLabel("密码:");
lq.setFont(new Font("宋体",Font.BOLD,20));
tf = new JTextField(10);
we = new JPasswordField(10);
we.setEchoChar('0');
ta = new JTextArea(5,10);
sp = new JScrollPane(ta);
bg = new ButtonGroup();
rb1 = new JRadioButton("男",true);
rb2 = new JRadioButton("女");
bg.add(rb1);
bg.add(rb2);

f.add(p);
p.add(l);
p.add(tf);
p.add(lq);
p.add(we);
//p.add(ta);
p.add(sp);
p.add(rb1);
p.add(rb2);

f.setVisible(true);
f.setSize(800, 600);
f.setLocation(560, 240);
p.setBackground(new Color(171,214,227));

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public static void main(String[] args) {
// TODO Auto-generated method stub
new SwingTest1();
}

}

 

猜你喜欢

转载自www.cnblogs.com/erlongi/p/10800630.html