List of usage examples for javax.swing JRadioButton addActionListener
public void addActionListener(ActionListener l)
ActionListener
to the button. From source file:MainClass.java
public MainClass() { JToggleButton tog = new JToggleButton("ToggleButton"); JCheckBox cb = new JCheckBox("CheckBox"); JRadioButton radio = new JRadioButton("RadioButton"); SimpleListener sl = new SimpleListener(); tog.addActionListener(sl);//from w ww. jav a 2 s .c o m cb.addActionListener(sl); radio.addActionListener(sl); Box buttonBox = new Box(BoxLayout.Y_AXIS); buttonBox.add(tog); buttonBox.add(cb); buttonBox.add(radio); undoButton.setEnabled(false); redoButton.setEnabled(false); undoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { edit.undo(); } catch (CannotUndoException ex) { ex.printStackTrace(); } finally { undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } } }); redoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { edit.redo(); } catch (CannotRedoException ex) { ex.printStackTrace(); } finally { undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } } }); Box undoRedoBox = new Box(BoxLayout.X_AXIS); undoRedoBox.add(Box.createGlue()); undoRedoBox.add(undoButton); undoRedoBox.add(Box.createHorizontalStrut(2)); undoRedoBox.add(redoButton); undoRedoBox.add(Box.createGlue()); Container content = getContentPane(); content.setLayout(new BorderLayout()); content.add(buttonBox, BorderLayout.CENTER); content.add(undoRedoBox, BorderLayout.SOUTH); setSize(400, 150); }
From source file:StrokeTest.java
/** * Makes a radio button to change the cap style. * @param label the button label/*w w w.j a v a 2s.c om*/ * @param style the cap style * @param group the radio button group */ private void makeCapButton(String label, final int style, ButtonGroup group) { // select first button in group boolean selected = group.getButtonCount() == 0; JRadioButton button = new JRadioButton(label, selected); buttonPanel.add(button); group.add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { canvas.setCap(style); } }); }
From source file:StrokeTest.java
/** * Makes a radio button to change the join style. * @param label the button label/* w w w . j a va 2 s . c om*/ * @param style the join style * @param group the radio button group */ private void makeJoinButton(String label, final int style, ButtonGroup group) { // select first button in group boolean selected = group.getButtonCount() == 0; JRadioButton button = new JRadioButton(label, selected); buttonPanel.add(button); group.add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { canvas.setJoin(style); } }); }
From source file:StrokeTest.java
/** * Makes a radio button to set solid or dashed lines * @param label the button label//from w w w. j a v a 2s .com * @param style false for solid, true for dashed lines * @param group the radio button group */ private void makeDashButton(String label, final boolean style, ButtonGroup group) { // select first button in group boolean selected = group.getButtonCount() == 0; JRadioButton button = new JRadioButton(label, selected); buttonPanel.add(button); group.add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { canvas.setDash(style); } }); }
From source file:UndoableToggleApp2.java
public UndoableToggleApp2() { JToggleButton tog = new JToggleButton("ToggleButton"); JCheckBox cb = new JCheckBox("CompoundEdit ExampleCheckBox"); JRadioButton radio = new JRadioButton("RadioButton"); SimpleListener sl = new SimpleListener(); tog.addActionListener(sl);//from ww w . j a v a 2s .c om cb.addActionListener(sl); radio.addActionListener(sl); Box buttonBox = new Box(BoxLayout.Y_AXIS); buttonBox.add(tog); buttonBox.add(cb); buttonBox.add(radio); undoButton.setEnabled(false); redoButton.setEnabled(false); endButton.setEnabled(false); undoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { edit.undo(); } catch (CannotUndoException ex) { ex.printStackTrace(); } finally { undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } } }); redoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { edit.redo(); } catch (CannotRedoException ex) { ex.printStackTrace(); } finally { undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } } }); endButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { edit.end(); endButton.setEnabled(false); undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } }); Box undoRedoEndBox = new Box(BoxLayout.X_AXIS); undoRedoEndBox.add(Box.createGlue()); undoRedoEndBox.add(undoButton); undoRedoEndBox.add(Box.createHorizontalStrut(2)); undoRedoEndBox.add(redoButton); undoRedoEndBox.add(Box.createHorizontalStrut(2)); undoRedoEndBox.add(endButton); undoRedoEndBox.add(Box.createGlue()); Container content = getContentPane(); content.setLayout(new BorderLayout()); content.add(buttonBox, BorderLayout.CENTER); content.add(undoRedoEndBox, BorderLayout.SOUTH); setSize(400, 150); }
From source file:SimpleDraw.java
public SimpleDraw() { this.setTitle("Simple DRAW"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // add check box group ButtonGroup cbg = new ButtonGroup(); JRadioButton lineButton = new JRadioButton("Line"); JRadioButton ovalButton = new JRadioButton("Oval"); JRadioButton rectangleButton = new JRadioButton("Rectangle"); cbg.add(lineButton);//w w w.j a v a2s . c om cbg.add(ovalButton); cbg.add(rectangleButton); lineButton.addActionListener(this); ovalButton.addActionListener(this); rectangleButton.addActionListener(this); rectangleButton.setSelected(true); JPanel radioPanel = new JPanel(new FlowLayout()); radioPanel.add(lineButton); radioPanel.add(ovalButton); radioPanel.add(rectangleButton); this.addMouseListener(this); this.setLayout(new BorderLayout()); this.add(radioPanel, BorderLayout.NORTH); }
From source file:de.tud.kom.p2psim.impl.skynet.visualization.MetricsPlot.java
private JRadioButton setJRadioButton(String title, boolean enable) { JRadioButton radioButton = new JRadioButton(title); radioButton.addActionListener(this); radioButton.setEnabled(enable);/* ww w.ja va 2s .co m*/ return radioButton; }
From source file:UndoableToggleApp.java
public UndoableToggleApp() { // Create some toggle buttons (and subclasses) JToggleButton tog = new JToggleButton("ToggleButton"); JCheckBox cb = new JCheckBox("CheckBox"); JRadioButton radio = new JRadioButton("RadioButton"); // Add our listener to each toggle button SimpleListener sl = new SimpleListener(); tog.addActionListener(sl);/*w w w.jav a 2 s . com*/ cb.addActionListener(sl); radio.addActionListener(sl); // Layout the buttons Box buttonBox = new Box(BoxLayout.Y_AXIS); buttonBox.add(tog); buttonBox.add(cb); buttonBox.add(radio); // Create undo and redo buttons (initially disabled) undoButton = new JButton("Undo"); redoButton = new JButton("Redo"); undoButton.setEnabled(false); redoButton.setEnabled(false); // Add a listener to the undo button. It attempts to call undo() on the // current edit, then enables/disables the undo/redo buttons as // appropriate. undoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { edit.undo(); } catch (CannotUndoException ex) { ex.printStackTrace(); } finally { undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } } }); // Add a redo listener: just like the undo listener, but for redo this // time. redoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { edit.redo(); } catch (CannotRedoException ex) { ex.printStackTrace(); } finally { undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } } }); // Layout the undo/redo buttons Box undoRedoBox = new Box(BoxLayout.X_AXIS); undoRedoBox.add(Box.createGlue()); undoRedoBox.add(undoButton); undoRedoBox.add(Box.createHorizontalStrut(2)); undoRedoBox.add(redoButton); undoRedoBox.add(Box.createGlue()); // Layout the main frame Container content = getContentPane(); content.setLayout(new BorderLayout()); content.add(buttonBox, BorderLayout.CENTER); content.add(undoRedoBox, BorderLayout.SOUTH); setSize(400, 150); }
From source file:UndoableToggleApp2.java
public UndoableToggleApp2() { // Create some toggle buttons (and subclasses) JToggleButton tog = new JToggleButton("ToggleButton"); JCheckBox cb = new JCheckBox("CompoundEdit ExampleCheckBox"); JRadioButton radio = new JRadioButton("RadioButton"); // Add our listener to each toggle button SimpleListener sl = new SimpleListener(); tog.addActionListener(sl);//from w ww .j a v a 2 s.c o m cb.addActionListener(sl); radio.addActionListener(sl); // Lay out the buttons Box buttonBox = new Box(BoxLayout.Y_AXIS); buttonBox.add(tog); buttonBox.add(cb); buttonBox.add(radio); // Create undo and redo buttons (initially disabled) undoButton = new JButton("Undo"); redoButton = new JButton("Redo"); endButton = new JButton("End"); undoButton.setEnabled(false); redoButton.setEnabled(false); endButton.setEnabled(false); // Add a listener to the undo button. It attempts to call undo() on the // current edit, then enables/disables the undo/redo buttons as // appropriate. undoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { edit.undo(); } catch (CannotUndoException ex) { ex.printStackTrace(); } finally { undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } } }); // Add a redo listener: just like the undo listener, but for redo this // time. redoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { edit.redo(); } catch (CannotRedoException ex) { ex.printStackTrace(); } finally { undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } } }); // Add an end listener. This listener will call end() on the // CompoundEdit // and update the undo/redo buttons. endButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { edit.end(); endButton.setEnabled(false); undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } }); // Layout the undo/redo/end buttons Box undoRedoEndBox = new Box(BoxLayout.X_AXIS); undoRedoEndBox.add(Box.createGlue()); undoRedoEndBox.add(undoButton); undoRedoEndBox.add(Box.createHorizontalStrut(2)); undoRedoEndBox.add(redoButton); undoRedoEndBox.add(Box.createHorizontalStrut(2)); undoRedoEndBox.add(endButton); undoRedoEndBox.add(Box.createGlue()); // Layout the main frame Container content = getContentPane(); content.setLayout(new BorderLayout()); content.add(buttonBox, BorderLayout.CENTER); content.add(undoRedoEndBox, BorderLayout.SOUTH); setSize(400, 150); }
From source file:RenderQualityTest.java
/** * Makes a set of buttons for a rendering hint key and values * //from w w w .j ava2s . c o m * @param key * the key name * @param value1 * the name of the first value for the key * @param value2 * the name of the second value for the key */ void makeButtons(String key, String value1, String value2) { try { final RenderingHints.Key k = (RenderingHints.Key) RenderingHints.class.getField(key).get(null); final Object v1 = RenderingHints.class.getField(value1).get(null); final Object v2 = RenderingHints.class.getField(value2).get(null); JLabel label = new JLabel(key); buttonBox.add(label, new GBC(0, r).setAnchor(GBC.WEST)); ButtonGroup group = new ButtonGroup(); JRadioButton b1 = new JRadioButton(value1, true); buttonBox.add(b1, new GBC(1, r).setAnchor(GBC.WEST)); group.add(b1); b1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { hints.put(k, v1); canvas.setRenderingHints(hints); } }); JRadioButton b2 = new JRadioButton(value2, false); buttonBox.add(b2, new GBC(2, r).setAnchor(GBC.WEST)); group.add(b2); b2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { hints.put(k, v2); canvas.setRenderingHints(hints); } }); hints.put(k, v1); r++; } catch (Exception e) { e.printStackTrace(); } }