文件名称:java 初步
文件大小:2KB
文件格式:JAVA
更新时间:2014-11-30 04:29:00
kuang
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class UserJFrame extends JFrame implements ActionListener{
private int number=1;
private JTextField text_number,text_name;
private JRadioButton radiob_male,radiob_female;
private Object cities[][];
private JComboBox combox_province,combox_city;
private JButton button_add;
private JTextArea text_user;
public UserJFrame(Object provinces[],Object cities[][])
{
super("输入用户信息");
this.setBounds(300,240,360,200);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.getContentPane().setLayout(new GridLayout(1,2));
text_user=new JTextArea();
this.getContentPane().add(text_user);
JPanel panel=new JPanel(new GridLayout(6,1));
this.getContentPane().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_rb=new JPanel(new GridLayout(1,2));
panel.add(panel_rb);
ButtonGroup bgroup=new ButtonGroup();
radiob_male=new JRadioButton("男 ",true);
bgroup.add(radiob_male);
panel_rb.add(radiob_male);
radiob_female=new JRadioButton("女");
bgroup.add(radiob_female);
panel_rb.add(radiob_female);
this.cities=cities;
combox_province=new JComboBox(provinces);
combox_province.setEditable(true);
combox_province.addActionListener(this);
panel.add(combox_province);
combox_city=new JComboBox(cities[0]);
panel.add(combox_city);
button_add=new JButton("添加");
button_add.addActionListener(this);
panel.add(button_add);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==combox_province)
{
int i=combox_province.getSelectedIndex();
combox_city.removeAllItems();
for(int j=0;j