【二级级联】
final JComboBox comboBox_1 = new JComboBox();
comboBox_1.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent arg0) {
int index=comboBox_1.getSelectedIndex();
switch(index){
case 0:
comboBox.removeAllItems();
break;
case 1:
comboBox.removeAllItems();
comboBox.addItem("临床医学");
comboBox.addItem("预防医学");
comboBox.addItem("药学");
break;
case 2:
comboBox.removeAllItems();
comboBox.addItem("计算机科学技术");
comboBox.addItem("软件工程");
comboBox.addItem("网络工程");
comboBox.addItem("信息安全");
break;
case 3:
comboBox.removeAllItems();
comboBox.addItem("环境工程");
comboBox.addItem("环境保护");
break;
}
}
});
【JRadioButton】
JRadioButton radioButton = new JRadioButton("\u7537");
JRadioButton radioButton_1 = new JRadioButton("\u5973");
ButtonGroup btnGroup=new ButtonGroup();
btnGroup.add(radioButton);
btnGroup.add(radioButton_1);
【提交】
JButton button = new JButton("\u63D0\u4EA4");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String s1=textField.getText();
String s2=textField_1.getText();
String s3=(String) comboBox_1.getSelectedItem();
String s4=(String) comboBox.getSelectedItem();
String s5= textField_2.getText();
String s6=(String) comboBox_2.getSelectedItem();
String s7=(String) comboBox_3.getSelectedItem();
String s8="";
if(radioButton.isSelected())
s8=radioButton.getText();
else if(radioButton_1.isSelected())
s8=radioButton_1.getText();
String ss1="";
if(checkBox.isSelected())
ss1=checkBox.getText();
else ss1="";
String ss2="";
if(checkBox_1.isSelected())
ss2=checkBox_1.getText();
else ss2="";
String ss3="";
if(checkBox_2.isSelected())
ss3=checkBox_2.getText();
else ss3="";
String ss4="";
if(checkBox_3.isSelected())
ss4=checkBox_3.getText();
else ss4="";
String ss5="";
if(checkBox_4.isSelected())
ss5=checkBox_4.getText();
else ss5="";
String s9=ss1+" "+ss2+" "+ss3+" "+ss4+" "+ss5;
String s10=textField_3.getText();
JFrame2 frame = new JFrame2(s1,s2,s3,s4,s5,s6,s7,s8,s9,s10);
frame.setVisible(true);
}
【重填】
JButton button_1 = new JButton("\u91CD\u586B");
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
textField.setText(" ");
textField_1.setText(" ");
textField_2.setText(" ");
textField_3.setText(" ");
checkBox.setSelected(false);
checkBox_1.setSelected(false);
checkBox_2.setSelected(false);
checkBox_3.setSelected(false);
checkBox_4.setSelected(false);
btnGroup.clearSelection();
comboBox_1.removeAllItems();
comboBox.removeAllItems();
comboBox_1.setModel(new DefaultComboBoxModel(new String[]{"","医学院","计算机学院","资环学院"}));
comboBox_2.setModel(new DefaultComboBoxModel(new String[]{"","湖北省","海南省","福建省"}));
comboBox_3.removeAllItems();
}
});