设置组合框可输入,并将输入字符串添加到组合框的下拉列表中 10

publicclassUserJFrameextendsJFrameimplementsActionListener{publicUserJFrame(Objectpro... public class UserJFrame extends JFrame implements ActionListener
{
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();
text_user.setEditable(false);
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<this.cities[i].length; j++)
combox_city.addItem(this.cities[i][j]);
} if (e.getSource() == button_add)
{ String aline=number+", "+text_name.getText();
if (radiob_male.isSelected())
aline += ", "+radiob_male.getText();
if (radiob_female.isSelected())
aline += ", "+radiob_female.getText();
aline += ", "+combox_province.getSelectedItem();
aline += ", "+combox_city.getSelectedItem();
text_user.append(aline+"\n");
this.number++;
text_number.setText(""+this.number);
text_name.setText("姓名");
}
}
public static void main(String arg[])
展开
 我来答
yangsong551
2010-12-09 · 超过15用户采纳过TA的回答
知道答主
回答量:60
采纳率:0%
帮助的人:38.4万
展开全部
好啊
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式