package JAVA_1;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
public class Register {
JButton zc = new JButton("注册");
JButton tc = new JButton();
JTextField txtName = new JTextField(10);
JTextField txtEmail = new JTextField(30);
JPasswordField txtPassword = new JPasswordField(10);
JTextArea txtResume = new JTextArea("备注信息");
JComboBox cobYear = new JComboBox(); //设置出生年份组合框
JComboBox cobMonth = new JComboBox(); //设置出生月份组合框
String[] s1 = {"博士","硕士","本科","专科","其他"};
JList list1 = new JList(s1);
JRadioButton sexM = new JRadioButton("男",true);
JRadioButton sexF = new JRadioButton("女");
ButtonGroup group = new ButtonGroup(); //new一个组,在下文中将男女加到一个组中,从而实现了单选功能;
JPanel sex = new JPanel(); //new 一个性别面板
JCheckBox c1 = new JCheckBox("逛街",true);
JCheckBox c2 = new JCheckBox("旅游",false);
JCheckBox c3 = new JCheckBox("运动",false);
JCheckBox c4 = new JCheckBox("看书",false);
JCheckBox c5 = new JCheckBox("上网",false);
public Register()
{
JFrame f = new JFrame("会员注册");
Toolkit kit = Toolkit.getDefaultToolkit(); //获取屏幕的大小
Dimension dim = kit.getScreenSize();
String title[] = {"昵称","密码","性别","出生年月","爱好","简历","学历","Email"};
JLabel jb[] =new JLabel[8];
for(int i=0; i<8; i++)
{
jb[i] = new JLabel(title[i]); //定义标签数组中的各按钮
jb[i].setHorizontalAlignment(SwingConstants.RIGHT);
}
txtPassword.setEchoChar('*'); //设置文本区回显字符为字符*;
group.add(sexM); //将单选按钮加入一个组group,那么就实现单选了!
group.add(sexF);
sex.add(jb[2]); //将性别加入sex面板
sex.add(sexM);
sex.add(sexF);
JPanel hobby = new JPanel(); //创建爱好面板
hobby.add(jb[4]);
hobby.add(c1);
hobby.add(c2);
hobby.add(c3);
hobby.add(c4);
hobby.add(c5);
list1.setSelectedIndex(2); //设定默认选择项
list1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list1.setSelectionBackground(Color.yellow);
list1.setBorder(BorderFactory.createLineBorder(Color.black));
JScrollPane lp = new JScrollPane(list1);
lp.setPreferredSize(new Dimension(80,80)); //显示最佳大小
for(int j=1960; j<2013; j++) // 设置列表选择框中的内容
{
cobYear.addItem(Integer.toString(j));
}
cobYear.setSelectedIndex(20); //设置第几个默认值;
for(int j=1; j<13; j++)
{
cobMonth.addItem(Integer.toString(j));
}
cobMonth.setSelectedIndex(0);
JPanel birth = new JPanel(); //new 一个生日面板
birth.add(jb[3]);
birth.add(cobYear);
birth.add(new JLabel("年"));
birth.add(cobMonth);
birth.add(new JLabel("月"));
txtResume.setLineWrap(true);
txtResume.setWrapStyleWord(true);
//JScrollPane jp = new JScrollPane(txtResume,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
JScrollPane jp = new JScrollPane();
jp.getViewport().setView(txtResume);
jp.setPreferredSize(new Dimension(150,80));
JPanel j1 = new JPanel();
j1.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 1));
j1.add(jb[5]);
j1.add(jp);
JPanel jNorth = new JPanel();
JPanel jNorth1 = new JPanel();
JPanel jNorth2 = new JPanel();
jNorth.setLayout(new GridLayout(2,1,8,8));
jNorth1.setLayout(new BoxLayout(jNorth1, BoxLayout.X_AXIS));
jNorth2.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 1));
jNorth1.add(jb[0]);
jNorth1.add(txtName);
jNorth1.add(jb[1]);
jNorth1.add(txtPassword);
jNorth2.add(jb[7]);
jNorth2.add(txtEmail);
jNorth.add(jNorth1);
jNorth.add(jNorth2);
JPanel jCenter = new JPanel();
jCenter.setLayout(new FlowLayout(FlowLayout.LEFT , 5, 1));
jCenter.add(sex);
jCenter.add(birth);
jCenter.add(hobby);
jCenter.add(j1);
jCenter.add(jb[6]);
jCenter.add(lp);
JPanel jSouth = new JPanel();
jSouth.setLayout(new FlowLayout(FlowLayout.LEFT, 80, 1));
tc.setText("退出");
jSouth.add(zc);
jSouth.add(tc);
f.setSize(390,270);
int w = f.getSize().width;
int h = f.getSize().height;
int x = (dim.width - w)/2;
int y = (dim.height - h)/2;
f.setLocation(x, y);
f.setVisible(true);
f.add(jSouth, BorderLayout.SOUTH);
f.add(jNorth, BorderLayout.NORTH);
f.add(jCenter, BorderLayout.CENTER);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame.setDefaultLookAndFeelDecorated(true);
new Register();
}
}