java - How to know what you selected in the JComboBox -
i making basic calculator app in java has 2 jtextfields , 1 jcombobox. want know if there way let jbutton detect selected in jcombobox, when did text field looked
static string divide = "/"; if (n == joptionpane.ok_option) { if (symbol.gettext().equals(divide)){ <code> } }
so there similar way jcomboboxs??
string[] symbols = {times, minus, plus, divide};
that's jcombobox's content code.
you can selected item jcombobox method .getselecteditem().
say have string[] symbols = {times, minus, plus, divide}; input when constructing jcombobox (see constructor jcombobox(e[] items) )
jcombobox jcb = new jcombobox(symbols); //you see string selected system.out.println(jcb.getselecteditem());
Comments
Post a Comment