-
Help with combo box
Hello I want to do an if statement that says if the user chooses Female it must do something and if the user chooses Male it must also do something. Help would very much appreciated! here is the code:
Code:
private void comboBox1MouseClicked(MouseEvent e)
{
if (comboBox1 == "Female")
{
//do something
}
else
{
if (comboBox1 == "Male")
{
//do something
}
}
}
-
Re: Help with combo box
Code:
if(comboBox1.getSelectedItem().equals("Female") {
// do something
} else if(comboBox1.getSelectedItem().equals("Male") {
// do something
}
-
Re: Help with combo box
- Don't check Strings for equality with ==, but instead use the equals(...) method.
- Check out and use the "else if" construct.
edit: as SRaith states above!
-
Re: Help with combo box
Thank you a lot Sraith and Mr Moderator!