Objectives
- Create graphical components
- Use layout managers
Create the GUI shown in the example. You do not have to provide any functionality. The three layout managers you should use are BorderLayout, FlowLayout, and GridLayout. Layouts can be nested using JPanels as containers for the nested layouts.
This is the GUI you have to create:
The following image has borders added to the JPanels that were used to group elements of the GUI. This should help you decide how to use JPanels, how to nest them, and how to set their layout managers.
The following examples may help with the assignment. The variable names can be any valid variable name.
Create a JPanel: JPanel pnl = new JPanel(); Create a label: JLabel lbl = new JLabel("Caption"); Create a button: JButton btn = new JButton("Caption"); Create a checkbox: JCheckBox cbox = new JCheckBox("Caption"); Create a "checked" checkbox: JCheckBox cbox = new JCheckBox("Caption", true); Create a radio button: JRadioButton rbtn = new JRadioButton("Caption"); Create a "selected" radio button: JRadioButton rbtn = new JRadioButton("Caption", true); Create an array of Strings for a combobox: String[] names = {"Al", "Bob", "Peg" }; Create a combobox: JComboBox combo = new JComboBox(names); Create a radio button group: ButtonGroup grp = new ButtonGroup(); Add a radiobutton to a buttongroup: grp.add(rbtn);