I Have two ComboBoxes
JcomboBox1.addItemListener(this)
jComboBox2.addItemListener(this)
How can I handle these in the same itemListener Function?
I am handling it for 1 combobox but need to handle with both combo box
public void itemStateChanged(ItemEvent ie) {
String Product=(String)jComboBox1.getSelectedItem();
ResultSet rs=db.GetPriceOfaProduct(Product);
try{
rs.next();
int price=rs.getInt("pPrice");
jLabel6.setText("Amount Per Item is "+price);
}catch(Exception e)
{
System.out.println("Error in Taking Product Price");
}
Use
ItemEvent.getSource()to check whichJComboBoxhas changed selection.Please be aware on changing selection, the item listener will be notified twice, once on the item deselected, followed by another on the item selected.