diff options
Diffstat (limited to 'examples/gnu/classpath/examples/swing/ButtonDemo.java')
-rw-r--r-- | examples/gnu/classpath/examples/swing/ButtonDemo.java | 116 |
1 files changed, 58 insertions, 58 deletions
diff --git a/examples/gnu/classpath/examples/swing/ButtonDemo.java b/examples/gnu/classpath/examples/swing/ButtonDemo.java index 1c6dfa01b..8b05dac13 100644 --- a/examples/gnu/classpath/examples/swing/ButtonDemo.java +++ b/examples/gnu/classpath/examples/swing/ButtonDemo.java @@ -43,23 +43,23 @@ import javax.swing.plaf.metal.MetalIconFactory; /** * A simple button demo showing various buttons in different states. */ -public class ButtonDemo - extends JPanel - implements ActionListener +public class ButtonDemo + extends JPanel + implements ActionListener { - private JCheckBox buttonState; + private JCheckBox buttonState; private JButton button1; private JButton button2; private JButton button3; private JButton button4; - private JCheckBox toggleState; + private JCheckBox toggleState; private JToggleButton toggle1; private JToggleButton toggle2; private JToggleButton toggle3; private JToggleButton toggle4; - + private JCheckBox checkBoxState; private JCheckBox checkBox1; private JCheckBox checkBox2; @@ -73,16 +73,16 @@ public class ButtonDemo /** * Creates a new demo instance. */ - public ButtonDemo() + public ButtonDemo() { createContent(); - // initFrameContent() is only called (from main) when running this app + // initFrameContent() is only called (from main) when running this app // standalone } - + /** * When the demo is run independently, the frame is displayed, so we should - * initialise the content panel (including the demo content and a close + * initialise the content panel (including the demo content and a close * button). But when the demo is run as part of the Swing activity board, * only the demo content panel is used, the frame itself is never displayed, * so we can avoid this step. @@ -100,10 +100,10 @@ public class ButtonDemo /** * Returns a panel with the demo content. The panel * uses a BorderLayout(), and the BorderLayout.SOUTH area - * is empty, to allow callers to add controls to the + * is empty, to allow callers to add controls to the * bottom of the panel if they want to (a close button is * added if this demo is being run as a standalone demo). - */ + */ private void createContent() { setLayout(new BorderLayout()); @@ -114,64 +114,64 @@ public class ButtonDemo panel.add(createRadioPanel()); add(panel); } - - private JPanel createButtonPanel() + + private JPanel createButtonPanel() { JPanel panel = new JPanel(new BorderLayout()); this.buttonState = new JCheckBox("Enabled", true); this.buttonState.setActionCommand("BUTTON_STATE"); this.buttonState.addActionListener(this); panel.add(this.buttonState, BorderLayout.EAST); - + JPanel buttonPanel = new JPanel(); buttonPanel.setBorder(BorderFactory.createTitledBorder("JButton")); this.button1 = new JButton("Button 1"); - + this.button2 = new JButton("Button 2"); this.button2.setIcon(MetalIconFactory.getInternalFrameDefaultMenuIcon()); - + this.button3 = new JButton("Button 3"); this.button3.setIcon(MetalIconFactory.getFileChooserHomeFolderIcon()); this.button3.setHorizontalTextPosition(SwingConstants.CENTER); this.button3.setVerticalTextPosition(SwingConstants.BOTTOM); - + this.button4 = new JButton("Button 4"); this.button4.setIcon(MetalIconFactory.getFileChooserUpFolderIcon()); this.button4.setText(null); - + buttonPanel.add(button1); buttonPanel.add(button2); buttonPanel.add(button3); buttonPanel.add(button4); - + panel.add(buttonPanel); - + return panel; } - - private JPanel createTogglePanel() + + private JPanel createTogglePanel() { JPanel panel = new JPanel(new BorderLayout()); - + this.toggleState = new JCheckBox("Enabled", true); this.toggleState.setActionCommand("TOGGLE_STATE"); this.toggleState.addActionListener(this); - + panel.add(this.toggleState, BorderLayout.EAST); - + JPanel buttonPanel = new JPanel(); buttonPanel.setBorder(BorderFactory.createTitledBorder("JToggleButton")); - + this.toggle1 = new JToggleButton("Toggle 1"); - + this.toggle2 = new JToggleButton("Toggle 2"); this.toggle2.setIcon(MetalIconFactory.getInternalFrameDefaultMenuIcon()); - + this.toggle3 = new JToggleButton("Toggle 3"); this.toggle3.setIcon(MetalIconFactory.getFileChooserHomeFolderIcon()); this.toggle3.setHorizontalTextPosition(SwingConstants.CENTER); this.toggle3.setVerticalTextPosition(SwingConstants.BOTTOM); - + this.toggle4 = new JToggleButton("Toggle 4"); this.toggle4.setIcon(MetalIconFactory.getFileChooserUpFolderIcon()); this.toggle4.setText(null); @@ -181,98 +181,98 @@ public class ButtonDemo toggleGroup.add(toggle2); toggleGroup.add(toggle3); toggleGroup.add(toggle4); - + buttonPanel.add(toggle1); buttonPanel.add(toggle2); buttonPanel.add(toggle3); buttonPanel.add(toggle4); - + panel.add(buttonPanel); - + return panel; } - private JPanel createCheckBoxPanel() + private JPanel createCheckBoxPanel() { JPanel panel = new JPanel(new BorderLayout()); - + this.checkBoxState = new JCheckBox("Enabled", true); this.checkBoxState.setActionCommand("CHECKBOX_STATE"); this.checkBoxState.addActionListener(this); - + panel.add(this.checkBoxState, BorderLayout.EAST); - + JPanel buttonPanel = new JPanel(); buttonPanel.setBorder(BorderFactory.createTitledBorder("JCheckBox")); this.checkBox1 = new JCheckBox("CheckBox 1"); - + this.checkBox2 = new JCheckBox("CheckBox 2"); - + this.checkBox3 = new JCheckBox("CheckBox 3"); - + buttonPanel.add(checkBox1); buttonPanel.add(checkBox2); buttonPanel.add(checkBox3); - + panel.add(buttonPanel); - + return panel; } - private JPanel createRadioPanel() + private JPanel createRadioPanel() { JPanel panel = new JPanel(new BorderLayout()); - + this.radioState = new JCheckBox("Enabled", true); this.radioState.setActionCommand("RADIO_STATE"); this.radioState.addActionListener(this); panel.add(this.radioState, BorderLayout.EAST); - + JPanel buttonPanel = new JPanel(); buttonPanel.setBorder(BorderFactory.createTitledBorder("JRadioButton")); this.radio1 = new JRadioButton("Radio 1"); - + this.radio2 = new JRadioButton("Radio 2"); - + this.radio3 = new JRadioButton("Radio 3"); - + ButtonGroup radioGroup = new ButtonGroup(); radioGroup.add(radio1); radioGroup.add(radio2); radioGroup.add(radio3); - + buttonPanel.add(radio1); buttonPanel.add(radio2); buttonPanel.add(radio3); - + panel.add(buttonPanel); - + return panel; } - - public void actionPerformed(ActionEvent e) + + public void actionPerformed(ActionEvent e) { - if (e.getActionCommand().equals("BUTTON_STATE")) + if (e.getActionCommand().equals("BUTTON_STATE")) { button1.setEnabled(buttonState.isSelected()); button2.setEnabled(buttonState.isSelected()); button3.setEnabled(buttonState.isSelected()); button4.setEnabled(buttonState.isSelected()); } - else if (e.getActionCommand().equals("TOGGLE_STATE")) + else if (e.getActionCommand().equals("TOGGLE_STATE")) { toggle1.setEnabled(toggleState.isSelected()); toggle2.setEnabled(toggleState.isSelected()); toggle3.setEnabled(toggleState.isSelected()); toggle4.setEnabled(toggleState.isSelected()); } - else if (e.getActionCommand().equals("CHECKBOX_STATE")) + else if (e.getActionCommand().equals("CHECKBOX_STATE")) { checkBox1.setEnabled(checkBoxState.isSelected()); checkBox2.setEnabled(checkBoxState.isSelected()); checkBox3.setEnabled(checkBoxState.isSelected()); } - else if (e.getActionCommand().equals("RADIO_STATE")) + else if (e.getActionCommand().equals("RADIO_STATE")) { radio1.setEnabled(radioState.isSelected()); radio2.setEnabled(radioState.isSelected()); @@ -284,7 +284,7 @@ public class ButtonDemo } } - public static void main(String[] args) + public static void main(String[] args) { SwingUtilities.invokeLater (new Runnable() |