Question: This assignment serves as our introduction to GUIs in Java. I'm having trouble with this assignment as it calls for us to use aspects of
This assignment serves as our introduction to GUIs in Java. I'm having trouble with this assignment as it calls for us to use aspects of java programming that weren't really covered in the materials provided, or explained in a way that makes it clear how to combine the various elements to create the desired program. I would appreciate it if someone could write a program that fulfills the assignments parameters, but also write notes that explain what each block of code is doing, and makes it more clear to me so I have the knowledge going forward.
It should be noted that we are not allowed to use javafx in this.
The gist of the instruction is to:
Java Program
Build a GUI that has the following
- A JComboBox with selections: Single and Multiple
- A JList with countries inside of it (an array of Strings). You don't have to use the same countries that I did.
- A JLabel that shows what is currently selected
Interactions
- When Single is selected then the JList changes so only one item can be selected.
- When Multiple is selected, the JList changes so multiple items can be selected
- When a country, or multiple countries, is selected the JLabel changes to reflect the new selections
Advice
Look at slides 37, 38 and 39 (GUI Access Example) to see how you can access other GUI items from within a listener.
The Lecture this week doesn't go through all of the examples. Look at the reading for this week for great examples on setting up JList and JComboBox.
Build an ActionListener for the JComboBox
- When it changes, change the JList's selection mode
Build a ListSelectionListener for the Jlist
- When the event occurs, call getSelectedIndices and getModel.getElementAt() to build a string listing everything selected
- Set the JLabel to the string you built
- Call .pack() on your base frame to resize it automatically
To try selecting multiple items in the list, hold down control or shift. By default the list will allow you to select multiple items.

Build a GUI that has the following 1. A JComboBox with selections: "Single" and "Multiple" 2. A JList with countries inside of it (an array of Strings). You don't have to use the same countries that I did. 3. A JLabel that shows what is currently selected Interactions 1. When "Single is selected then the JList changes so only one item can be selected. 2. When "Multiple" is selected, the JList changes so multiple items can be selected 3. When a country, or multiple countries, is selected the JLabel changes to reflect the new selections Advice Look at slides 37, 38 and 39 (GUI Access Example) to see how you can access other GUI items from within a listener. The Lecture this week doesn't go through all of the examples. Look at the reading for this week for great examples on setting up List and JComboBox. Build an ActionListener for the ComboBox . When it changes, change the JList's selection mode Build a List SelectionListener for the Jlist When the event occurs, call getSelectedIndices and getModel.getElementAt() to build a string listing everything selected Set the JLabel to the string you built Call.pack() on your base frame to resize it automatically To try selecting multiple items in the list, hold down control or shift. By default the list will allow you to select multiple items. Choose Selection Mode: Single- Choose Selection Mode: Single Bahamas Costa Rica Canada Cuba Haiti Jamaica Mexico United States of America Selected items will appear here Bahamas Costa Rica Canada Cuba Haiti Jamaica Mexico United States of America Selected items: Haiti Choose Selection Mode: Multiple - Bahamas Costa Rica Canada Cuba Haiti Jamaica Mexico United States of America Selected items: Canada Jamaica Mexico
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
