final JComboBox comboBox_6 = new JComboBox(); //創建combobox對象 comboBox_6.setBounds(470, 10, 44, 23); comboBox_6.setSelectedIndex(DD1-1); comboBox_5.addItemListener(new ItemListener() //添加監聽事件 { @Override public void itemStateChanged(ItemEvent e){ //通過監聽combobox中值的改變,獲得改變后的索引值 if(list1.contains(comboBox_5.getSelectedItem())){ System.out.println("123"); comboBox_6.setModel(new DefaultComboBoxModel(day)); System.out.println(comboBox_5.getSelectedItem()); System.out.println(new DefaultComboBoxModel(day)); //combobox的setModel方法是創建或者改變combobox的索引列表 } if(list2.contains(comboBox_5.getSelectedItem())){ System.out.println("123"); if( YY1%4 == 0){ comboBox_6.setModel(new DefaultComboBoxModel(day2)); System.out.println(comboBox_5.getSelectedItem()); System.out.println(new DefaultComboBoxModel(day2)); }else{ comboBox_6.setModel(new DefaultComboBoxModel(day3)); System.out.println(comboBox_5.getSelectedItem()); System.out.println(new DefaultComboBoxModel(day3)); } } if(list3.contains(comboBox_5.getSelectedItem())){ System.out.println("123"); comboBox_6.setModel(new DefaultComboBoxModel(day1)); System.out.println(comboBox_5.getSelectedItem()); System.out.println(new DefaultComboBoxModel(day1)); } } });
