package picture;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class UserJFrame extends JFrame implements ActionListener,ItemListener {
private int number=1; //编号
private JTextField text_number,text_name; //编号,姓名文本行
private JRadioButton radiobutton_male,radiobutton_female; //性别按钮
private JComboBox combobox_province,combobox_city; //省份,城市组合框
private JButton button_add; //添加按钮
private JTextArea text_user; //文本区
public UserJFrame()
{
super("输入用户信息");
this.setSize(360,200);
this.setLocation(300,240);
this.setDefaultCloseOperation(EXIT_ON_CLOSE); //单击窗口关闭按钮时,结束程序的运行
this.setLayout(new GridLayout(1,2)); //网格布局,1行2列,左右分隔窗口
text_user=new JTextArea(); //创建文本区
this.add(text_user); //占据窗口左半部分
JPanel panel=new JPanel(new GridLayout(6,1)); //面板网格布局,6行1列
this.add(panel); //占据窗口的右半部分
text_number=new JTextField("1"); //编号文本行
text_number.setEditable(false); //不可编辑,自动生成编号
panel.add(text_number);
text_name=new JTextField("姓名");
panel.add(text_name);
JPanel panel_radiobutton=new JPanel(new GridLayout(1,2)); //单选按钮子面板,网格
panel.add(panel_radiobutton);
ButtonGroup buttongroup=new ButtonGroup(); //按钮组
radiobutton_male=new JRadioButton("男",true);
buttongroup.add(radiobutton_male); //单选按钮添加到按钮组
panel_radiobutton.add(radiobutton_male); //单选按钮添加到子面板
radiobutton_female=new JRadioButton("女");
buttongroup.add(radiobutton_female);
panel_radiobutton.add(radiobutton_female);
Object province[]={"江苏省","浙江省"};
combobox_province=new JComboBox(province); //省份组合框
combobox_province.addItemListener(this); //注册组合框的选择事件监听器
panel.add(combobox_province);
Object city[]={"南京市","苏州市","无锡市"};
combobox_city=new JComboBox(city);
panel.add(combobox_city);
button_add=new JButton("添加");
button_add.addActionListener(this);
panel.add(button_add);
this.setVisible(true);