2013-08-24 112 views
0

我在addListSelectionListener中有一個確認對話框。當我在表格中選擇一行時,這會引發火災。然後出現確認對話框,然後點擊是或否,它會一直出現!確認對話框出現多次

這是我的代碼。

public Reference() { 
    initComponents(); 
    fillTable(); 
    jTable1.getSelectionModel().addListSelectionListener(new ListSelectionListener() { 
     public void valueChanged(ListSelectionEvent e) { 
      int prompt = JOptionPane.showConfirmDialog(null, "Are you sure you want to Check Out this item?", "Warning", JOptionPane.YES_NO_OPTION); 
      if (prompt == 0) { 
       String accessNo = jTable1.getValueAt(jTable1.getSelectedRow(), 0).toString(); 
       String query = "delete from reference where accessNo=" + accessNo + ""; 
       if (DB.executeNonQuery(query) > 0) { 
        JOptionPane.showMessageDialog(null, "Check out Successfull!"); 
        fillTable(); 
       } else { 
        JOptionPane.showMessageDialog(null, "Check out Failed!"); 
       } 
      } 
     } 
    }); 
} 

回答