public void findAndAddFlavor() { //Retrieve the new flavor String inputFlavorString = inputTextField.getText(); //Search the items for a match boolean foundFlavorBoolean = findDuplicate(inputFlavorString); if(foundFlavorBoolean) if (addBagelRadioButton.isSelected()) JOptionPane.showMessageDialog(null, "item is already in the list"); else { JOptionPane.showMessageDialog(null, "item is already in the list"); } else if (addBagelRadioButton.isSelected()) { bagelComboBox.addItem(inputFlavorString); JOptionPane.showMessageDialog(null, "item added to the list"); } else { cheeseComboBox.addItem(inputFlavorString); JOptionPane.showMessageDialog(null, "item added to the list"); } } public boolean findDuplicate(String inputString) { boolean itemFoundBoolean = false; String listItemString = ""; int indexInteger = 0; int indexInteger2 = 0; int numberBagelInteger = bagelComboBox.getItemCount(); //Gets number in combo box outputTextArea.append("\nTotal count in combo is: " + numberBagelInteger); int numberCreamCheeseInteger = cheeseComboBox.getItemCount(); //Gets number in combo box outputTextArea.append("\nTotal count in combo is: " + numberCreamCheeseInteger); if (!itemFoundBoolean && indexInteger < numberBagelInteger) { {listItemString = String.valueOf(bagelComboBox.getItemAt(indexInteger)); if(inputString.equalsIgnoreCase(listItemString)) { itemFoundBoolean = true; } indexInteger++; } else if (!itemFoundBoolean && indexInteger2 < numberCreamCheeseInteger) { listItemString = String.valueOf(cheeseComboBox.getItemAt(indexInteger2)); { if(inputString.equalsIgnoreCase(listItemString)) { itemFoundBoolean = true; } indexInteger2++; } } return itemFoundBoolean; }
listItemString = String.valueOf(bagelComboBox.getItemAt(indexInteger));
valueOf()
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)