I am writing a program for a college assignment, creating objects and storing them in an array, other options will be there too.
I am trying to figure out how to use JComboBoxes, to give the user set options, instead of:
Please select an option: Press 1 for x Press 2 for y ________
How can I go about having a JComboBox put into the message [] and then display it? Other windows displayed to the user would have probably 2 or 3 JComboBoxes, so if I can get it sorted for the one, I can for the others....I hope.
public void menuArmourOrWeapon() { int option = 0; String msgInfo = new String("Please choose which type of item you wish to add."); String msgArmour = new String("1. Armour"); String msgWeapon = new String("2. Weapon"); JTextField input = new JTextField(""); Object message[] = new Object[5]; message[0] = myIcon; message[1] = msgInfo; message[2] = msgArmour; message[3] = msgWeapon; message[4] = input; int response = JOptionPane.showConfirmDialog(null, message, "Item Data Entry", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, anIcon); if(response == JOptionPane.CANCEL_OPTION) { } else { try { option = Integer.parseInt(input.getText()); if(option == 1) { augment(option); } else if (option == 2) { augment(option); } } catch (Exception e) { JOptionPane.showMessageDialog(null, "Data Input Error" + e + "\nPlease Try Again"); } } }