0

Looking for some help. I have a list of planes (strings) in a combo box to be selected by the user and when a particular plane is selected I want to be able reference it. I am mostly self-taught so bear with me.
Link to download full code

String[] planeTitles = new String[] {"Focke-Wulf Fw 190", "Messerschmitt Bf 109","Messerschmitt Me 262", "Supermarine MKs 24 Spitfire",
                                    "Yakovlev Yak-3", "Vought F4U Corsair", "Lockheed P-38 Lightning", "North American P-51 Mustang", "Mitsubishi A6M Zero"};

      JComboBox<String> planeList = new JComboBox<>(planeTitles);

// add to the parent container (e.g. a JFrame):

add(planeList);

// get the selected item:

planeList.addActionListener (
            new ActionListener () {
               public void actionPerformed(ActionEvent e) {
                  String selectedPlane = (String) planeList.getSelectedItem();
                  System.out.println("You seleted the: " + selectedPlane);

                  textPane.setText("You seleted the: " + selectedPlane);


               }
            });

The planes later need to compare to user generated data. Basically my question is how would you create an object for each plane and assign it to my current list of planes? I know it is probably a bit much to ask...

  • Does the user input need to be saved forever, i.e. if user gives input and the program is closed, does the user input need to be in the list on next program start? If so, you'll need to save your planes in a file. See the following answer on this site for more information on writing to files: http://stackoverflow.com/questions/2885173/how-to-create-a-file-and-write-to-a-file-in-java – Tobias Brösamle May 20 '16 at 07:58
  • If this a more serious undertaking ... then the idea of putting a simple array into your combo box will simply become a major problem for your application. Meaning: Probably the types of planes that need to be supported is a core "property" of your application. In that sense you to model the internal representation of "planes" with great care; and then you might use concepts as https://docs.oracle.com/javase/tutorial/uiswing/components/model.html to connect your "data model" to the actual UI. – GhostCat May 20 '16 at 08:02

0 Answers0