Page 766 - Introduction to Programming with Java: A Problem Solving Approach
P. 766
732 Chapter 17 GUI Programming—Component Layout, Additional GUI Components
private void createContents()
{
}
ButtonGroup radioGroup;
// Note:
// The most straightforward implementation is to use a
// GridLayout manager for the JFrame and add all components
// to its cells. That doesn't work well because:
// 1) Can't apply a margin to JFrame.
// 2) The button panel is taller than the other components.
// Need windowPanel for south-panel separation & outer margin
JPanel windowPanel = new JPanel(new BorderLayout(0, 10));
windowPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
// centerPanel holds all components except button
JPanel centerPanel = new JPanel(new GridLayout(11, 1));
// Need a panel for button so it can be center aligned
JPanel southPanel = new JPanel(new FlowLayout());
java = new JCheckBox("Java Sun certified");
helpDesk = new JCheckBox("help-desk experience");
coffee = new JCheckBox("able to make good coffee");
goodCitizen = new JRadioButton("law-abiding citizen");
Apago PDF Enhancer
criminal = new JRadioButton("violent criminal");
radioGroup = new ButtonGroup();
radioGroup.add(goodCitizen);
radioGroup.add(criminal);
salary = new JComboBox(salaryOptions);
submit = new JButton("Submit");
submit.addActionListener(new ButtonListener());
centerPanel.add(new JLabel("Skills (check all that apply):"));
centerPanel.add(java);
centerPanel.add(helpDesk);
centerPanel.add(coffee);
centerPanel.add(new JLabel()); // filler
centerPanel.add(new JLabel("Community standing:"));
centerPanel.add(goodCitizen);
centerPanel.add(criminal);
centerPanel.add(new JLabel()); // filler
centerPanel.add(new JLabel("Salary requirements:"));
centerPanel.add(salary);
windowPanel.add(centerPanel, BorderLayout.CENTER);
southPanel.add(submit);
windowPanel.add(southPanel, BorderLayout.SOUTH);
add(windowPanel);
// end createContents
Figure 17.17b JobApplication program—part B