这是我的代码的一部分,我遇到的问题是我无法从我的列表中选择项目(当我的界面运行时我不能按项目来选择它)!..
DefaultListModel model = new DefaultListModel ();
JList list=new JList(model);
comboBox_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox comboBox_2 = (JComboBox) e.getSource();
Object selected = comboBox.getSelectedItem();
Object selected_2 = comboBox_2.getSelectedItem();
if(selected.toString().equals("1")) {
if (selected_2.toString().equals("Oils")) {
try{
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/flyer","root","000");
String query="SELECT item_name FROM item WHERE ( month(expired_date) = month(curdate()) AND day(expired_date) >= day(curdate()) AND year(expired_date) = year(curdate()) AND category_id=1) OR ( month(expired_date) = month(curdate()) +1 AND day(expired_date) <= day(curdate()) AND year(expired_date) = year(curdate()) AND category_id=1) ";
Statement st= conn.createStatement();
ResultSet r=st.executeQuery(query);
model.removeAllElements();
while(r.next()){
String itemCode = r.getString("item_name");
model.addElement(itemCode);
}}
catch (Exception ex){
System.err.println(e);
}}
答案 0 :(得分:2)
检查您的输出,看看您是否收到任何例外情况。此外,您正尝试在catch(Exception ex)
块中打印动作侦听器。