关于界面的问题 怎么把选择的上海长沙也像男女一样输出来啊
package newer.javax;import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Vector;
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.JPanel;
import javax.swing.JRadioButton;
import newer.javax.Demo4.MyActionListener;
public class Frame extends JFrame{
JLabel jLabel1=new JLabel("户籍");
JComboBox jComboBox1=new JComboBox();
// JRadioButton jRadioButton1=new JRadioButton("男",true);
// JRadioButton jRadioButton2=new JRadioButton();
ButtonGroup buttonGroup1=new ButtonGroup();
ArrayList<JCheckBox> checkBoxs = new ArrayList<JCheckBox>();
JComboBox list1= null;
public Frame(){
super("表单组件示例");
JLabel lbl1 = new JLabel();//创建文本标签lbl1
lbl1.setText("用户基本信息 ");
this.getContentPane().add(lbl1);
setSize(300,300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
this.getContentPane().setLayout(new FlowLayout());
this.getContentPane().add(jLabel1);
jComboBox1.addItem("长沙");
jComboBox1.addItem("上海");
list1 = new JComboBox();
this.getContentPane().add(jComboBox1);
this.getContentPane().add(list1);
//复选框示例
JCheckBox jCeckBox1=new JCheckBox("C");
JCheckBox jCeckBox2=new JCheckBox("SQL");
JCheckBox jCeckBox3=new JCheckBox("HTML");
JCheckBox jCeckBox4=new JCheckBox("JAVA");
checkBoxs.add(jCeckBox1);
checkBoxs.add(jCeckBox2);
checkBoxs.add(jCeckBox3);
checkBoxs.add(jCeckBox4);
this.getContentPane().add(jCeckBox1);
this.getContentPane().add(jCeckBox2);
this.getContentPane().add(jCeckBox3);
this.getContentPane().add(jCeckBox4);
//单选按钮示例
// jRadioButton2.setText("女");
// this.getContentPane().setLayout(new FlowLayout());
// this.getContentPane().add(jRadioButton1);
// this.getContentPane().add(jRadioButton2);
// buttonGroup1.add(jRadioButton1);
// buttonGroup1.add(jRadioButton2);
JCheckBox box1 = new JCheckBox("男");
box1.setSize(40,20);
box1.setLocation(20,20);
JCheckBox box2 = new JCheckBox("女");
box2.setSize(40,20);
box2.setLocation(20,60);
checkBoxs.add(box1);
checkBoxs.add(box2);
this.getContentPane().add(box1);
this.getContentPane().add(box2);
buttonGroup1.add(box1);
buttonGroup1.add(box2);
JButton btn1 = new JButton();//创建按钮对象
btn1.setText("确定");
this.getContentPane().add(btn1);
btn1.addActionListener(new MyActionListener());
this.setVisible(true);
}
class MyActionListener implements ActionListener{
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
for(int i=0;i<checkBoxs.size();i++){
JCheckBox checkBox = checkBoxs.get(i);
if(checkBox.isSelected()){
System.out.println("你选择了:"+checkBox.getText());
}
}
}//System.out.print(list1.getSelectedItem());
}
public static void main(String [] args){
Frame showJComboBox1=new Frame();
}
}