Make an if statement generic
Hi,
I have to use if statement three times for three different jComboBoxes. I was wondering if there was a way I could achieve this so I do I have to repeat my if statement 3 times.
Could I use a loop? or since the if statement is small how could I write a generic if statement that would work with any combobox?
Here is my awesome code!! haha
int id;
if (jComboBoxDirectory.getSelectedIndex() == 0)
id= 1;
else if (jComboBoxDirectory.getSelectedIndex() == 1)
id = 2;
else if (jComboBoxDirectory.getSelectedIndex() == 2)
id = 3;
else
id = 4;
Thanks in advance!

