JComboBox and IF Statement
Hello,
I am new to Java, and have been trying to make a program for my college course. I have come to a bit of a dead end.
I am trying to make a JComboBox that is linked to a If statement.
e.g.
I want to make a JComboBox with three options (Natural, Yorkstone and Clay) and then create an If statement for it like (pseudocode):
if (JComboBox = Natural)
type = 1;
else if (JComboBox = Yorkstone);
type = 2;
else
type = 3;
Any ideas would be greatly appreceated.
Thanks in advance. :)
I haven't "linked" the if statement...
.. to anything here, but this should work :)
Code:
JComboBox box=new JComboBox();
.
.
box.addItem("Natural");
box.addItem("Yorkstone");
box.addItem("Clay");
.
.
if (box.getSelectedItem().equals("Natural"))
type=1;
if (box.getSelectedItem().equals("Yorkstone"))
type=2;
if (box.getSelectedItem().equals("Clay"))
type=3;