Two
Here is the part of the program for
the gender buttons.
The buttons are added to
(1) genderPanel
, which
controls their graphic representation
on screen, and added to (2)
genderGroup
, which controls
their logical operation.
BoxLayout
is used to put the
label and the two radio buttons in a vertical column.
The JLabel
is constructed and
added to the panel in a single statement.
This is fine, since there will be no need to
refer to the label as a variable.
public class IdealWeight extends JFrame { JRadioButton genderM; JRadioButton genderF; ButtonGroup genderGroup; JPanel genderPanel; . . . . public IdealWeight() { // gender group genderM = new JRadioButton("Male", true ); genderF = new JRadioButton("Female", false ); genderGroup = new ButtonGroup(); genderGroup.add( genderM ); genderGroup.add( genderF ); genderPanel = new JPanel(); genderPanel.setLayout( new BoxLayout(_________ , _________)); genderPanel.add( new JLabel("Your Gender") ); genderPanel.add( genderM ); genderPanel.add( genderF ); . . . . .