//Chap138.java //chapter 13.8 method C //container is FlowLayout, JPanels each //a GridLayout import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Chap138C extends JApplet implements ActionListener { private JCheckBox snapCheckBox; private JCheckBox showCheckBox; private JLabel xLabel; private JTextField xField; private JLabel yLabel; private JTextField yField; private JButton okButton; private JButton helpButton; private JButton cancelButton; //this differs in each version of Chap138: private FlowLayout layout; private JPanel checkboxesPanel; private JPanel textfieldsPanel; private JPanel buttonsPanel; public void init() { layout = new FlowLayout( ); layout.setAlignment( FlowLayout.CENTER ); // get content pane and set its layout Container container = getContentPane(); container.setLayout( layout ); snapCheckBox = new JCheckBox( "Snap to Grid" ); showCheckBox = new JCheckBox( "Show Grid" ); checkboxesPanel = new JPanel(); checkboxesPanel.setLayout( new GridLayout( 2, 1, 0, 0 ) ); checkboxesPanel.add( snapCheckBox ); checkboxesPanel.add( showCheckBox ); container.add( checkboxesPanel ); xLabel = new JLabel( "X:" ); xField = new JTextField( "8", 4 ); yLabel = new JLabel( "Y:" ); yField = new JTextField( "8", 4 ); textfieldsPanel = new JPanel(); textfieldsPanel.setLayout( new GridLayout( 2, 2, 0, 0 ) ); textfieldsPanel.add( xLabel ); textfieldsPanel.add( xField ); textfieldsPanel.add( yLabel ); textfieldsPanel.add( yField ); container.add( textfieldsPanel ); okButton = new JButton( "Ok" ); cancelButton = new JButton( "Help" ); helpButton = new JButton( "Cancel" ); buttonsPanel = new JPanel(); buttonsPanel.setLayout( new GridLayout( 3, 1, 0, 0 ) ); buttonsPanel.add( okButton ); buttonsPanel.add( cancelButton ); buttonsPanel.add( helpButton ); container.add( buttonsPanel ); } public void actionPerformed( ActionEvent event ) { } }