genderPanel = new JPanel(); genderPanel.setLayout( new BoxLayout(genderPanel , BoxLayout.Y_AXIS));
Here is the section of the code that
deals with the buttons for height.
The buttons are added to
heightPanel
, and to
heightGroup
.
One button of the heightGroup
is
set to be chosen by default.
As with the gender buttons, BoxLayout
is used in the panel to put the label and
buttons in a column.
public class IdealWeight extends JFrame { JRadioButton heightA; JRadioButton heightB; JRadioButton heightC; JRadioButton heightD; JRadioButton heightE; ButtonGroup heightGroup; JPanel heightPanel; public IdealWeight() { // height group heightA = new JRadioButton("60 to 64 inches",false); heightB = new JRadioButton("64 to 68 inches",false); heightC = new JRadioButton("68 to 72 inches",false); heightD = new JRadioButton("72 to 76 inches",true ); // Default Choice heightE = new JRadioButton("76 to 80 inches",false); heightGroup = new ButtonGroup(); heightGroup.add( ); heightGroup.add( ); heightGroup.add( ); heightGroup.add( ); heightGroup.add( ); heightPanel = new JPanel(); heightPanel.setLayout( new BoxLayout(heightPanel,BoxLayout.Y_AXIS) ); heightPanel.add( new JLabel("Your Height") ); heightPanel.add( ); heightPanel.add( ); heightPanel.add( ); heightPanel.add( ); heightPanel.add( ); . . . . . } }
Add the buttons to the button group and to the panel.
(If you use copy-and-paste, this is not nearly as tedious as you might think.)