< prev index next >

src/demo/share/jfc/SwingSet2/ButtonDemo.java

Print this page




  44 import java.beans.*;
  45 import java.util.*;
  46 import java.io.*;
  47 import java.applet.*;
  48 import java.net.*;
  49 
  50 /**
  51  * JButton, JRadioButton, JToggleButton, JCheckBox Demos
  52  *
  53  * @author Jeff Dinkins
  54  */
  55 public class ButtonDemo extends DemoModule implements ChangeListener {
  56 
  57     JTabbedPane tab;
  58 
  59     JPanel buttonPanel = new JPanel();
  60     JPanel checkboxPanel = new JPanel();
  61     JPanel radioButtonPanel = new JPanel();
  62     JPanel toggleButtonPanel = new JPanel();
  63 
  64     Vector buttons = new Vector();
  65     Vector checkboxes = new Vector();
  66     Vector radiobuttons = new Vector();
  67     Vector togglebuttons = new Vector();
  68 
  69     Vector currentControls = buttons;
  70 
  71     JButton button;
  72     JCheckBox check;
  73     JRadioButton radio;
  74     JToggleButton toggle;
  75 
  76     EmptyBorder border5 = new EmptyBorder(5,5,5,5);
  77     EmptyBorder border10 = new EmptyBorder(10,10,10,10);
  78 
  79     ItemListener buttonDisplayListener = null;
  80     ItemListener buttonPadListener = null;
  81 
  82     Insets insets0 = new Insets(0,0,0,0);
  83     Insets insets10 = new Insets(10,10,10,10);
  84 
  85     /**
  86      * main method allows us to run as a standalone demo.
  87      */
  88     public static void main(String[] args) {
  89         ButtonDemo demo = new ButtonDemo(null);


 449         tenPad.setMnemonic(getMnemonic("ButtonDemo.ten_mnemonic"));
 450         tenPad.setToolTipText(getString("ButtonDemo.ten_tooltip"));
 451         tenPad.addItemListener(buttonPadListener);
 452         group.add(tenPad);
 453         leftColumn.add(tenPad);
 454 
 455         leftColumn.add(Box.createRigidArea(VGAP20));
 456         return controls;
 457     }
 458 
 459     public void createListeners() {
 460         buttonDisplayListener = new ItemListener() {
 461                 Component c;
 462                 AbstractButton b;
 463 
 464                 public void itemStateChanged(ItemEvent e) {
 465                     JCheckBox cb = (JCheckBox) e.getSource();
 466                     String command = cb.getActionCommand();
 467                     if(command == "Enabled") {
 468                         for(int i = 0; i < currentControls.size(); i++) {
 469                             c = (Component) currentControls.elementAt(i);
 470                             c.setEnabled(cb.isSelected());
 471                             c.invalidate();
 472                         }
 473                     } else if(command == "PaintBorder") {
 474                         c = (Component) currentControls.elementAt(0);
 475                         if(c instanceof AbstractButton) {
 476                             for(int i = 0; i < currentControls.size(); i++) {
 477                                 b = (AbstractButton) currentControls.elementAt(i);
 478                                 b.setBorderPainted(cb.isSelected());
 479                                 b.invalidate();
 480                             }
 481                         }
 482                     } else if(command == "PaintFocus") {
 483                         c = (Component) currentControls.elementAt(0);
 484                         if(c instanceof AbstractButton) {
 485                             for(int i = 0; i < currentControls.size(); i++) {
 486                                 b = (AbstractButton) currentControls.elementAt(i);
 487                                 b.setFocusPainted(cb.isSelected());
 488                                 b.invalidate();
 489                             }
 490                         }
 491                     } else if(command == "ContentFilled") {
 492                         c = (Component) currentControls.elementAt(0);
 493                         if(c instanceof AbstractButton) {
 494                             for(int i = 0; i < currentControls.size(); i++) {
 495                                 b = (AbstractButton) currentControls.elementAt(i);
 496                                 b.setContentAreaFilled(cb.isSelected());
 497                                 b.invalidate();
 498                             }
 499                         }
 500                     }
 501                     invalidate();
 502                     validate();
 503                     repaint();
 504                 }
 505         };
 506 
 507         buttonPadListener = new ItemListener() {
 508                 Component c;
 509                 AbstractButton b;
 510 
 511                 public void itemStateChanged(ItemEvent e) {
 512                     // *** pad = 0


 532                     invalidate();
 533                     validate();
 534                     repaint();
 535                 }
 536         };
 537     }
 538 
 539     public void stateChanged(ChangeEvent e) {
 540         SingleSelectionModel model = (SingleSelectionModel) e.getSource();
 541         if(model.getSelectedIndex() == 0) {
 542             currentControls = buttons;
 543         } else if(model.getSelectedIndex() == 1) {
 544             currentControls = radiobuttons;
 545         } else if(model.getSelectedIndex() == 2) {
 546             currentControls = checkboxes;
 547         } else {
 548             currentControls = togglebuttons;
 549         }
 550     }
 551 
 552     public Vector getCurrentControls() {
 553         return currentControls;
 554     }
 555 }


  44 import java.beans.*;
  45 import java.util.*;
  46 import java.io.*;
  47 import java.applet.*;
  48 import java.net.*;
  49 
  50 /**
  51  * JButton, JRadioButton, JToggleButton, JCheckBox Demos
  52  *
  53  * @author Jeff Dinkins
  54  */
  55 public class ButtonDemo extends DemoModule implements ChangeListener {
  56 
  57     JTabbedPane tab;
  58 
  59     JPanel buttonPanel = new JPanel();
  60     JPanel checkboxPanel = new JPanel();
  61     JPanel radioButtonPanel = new JPanel();
  62     JPanel toggleButtonPanel = new JPanel();
  63 
  64     Vector<Component> buttons = new Vector<>();
  65     Vector<Component> checkboxes = new Vector<>();
  66     Vector<Component> radiobuttons = new Vector<>();
  67     Vector<Component> togglebuttons = new Vector<>();
  68 
  69     Vector<Component> currentControls = buttons;
  70 
  71     JButton button;
  72     JCheckBox check;
  73     JRadioButton radio;
  74     JToggleButton toggle;
  75 
  76     EmptyBorder border5 = new EmptyBorder(5,5,5,5);
  77     EmptyBorder border10 = new EmptyBorder(10,10,10,10);
  78 
  79     ItemListener buttonDisplayListener = null;
  80     ItemListener buttonPadListener = null;
  81 
  82     Insets insets0 = new Insets(0,0,0,0);
  83     Insets insets10 = new Insets(10,10,10,10);
  84 
  85     /**
  86      * main method allows us to run as a standalone demo.
  87      */
  88     public static void main(String[] args) {
  89         ButtonDemo demo = new ButtonDemo(null);


 449         tenPad.setMnemonic(getMnemonic("ButtonDemo.ten_mnemonic"));
 450         tenPad.setToolTipText(getString("ButtonDemo.ten_tooltip"));
 451         tenPad.addItemListener(buttonPadListener);
 452         group.add(tenPad);
 453         leftColumn.add(tenPad);
 454 
 455         leftColumn.add(Box.createRigidArea(VGAP20));
 456         return controls;
 457     }
 458 
 459     public void createListeners() {
 460         buttonDisplayListener = new ItemListener() {
 461                 Component c;
 462                 AbstractButton b;
 463 
 464                 public void itemStateChanged(ItemEvent e) {
 465                     JCheckBox cb = (JCheckBox) e.getSource();
 466                     String command = cb.getActionCommand();
 467                     if(command == "Enabled") {
 468                         for(int i = 0; i < currentControls.size(); i++) {
 469                             c = currentControls.elementAt(i);
 470                             c.setEnabled(cb.isSelected());
 471                             c.invalidate();
 472                         }
 473                     } else if(command == "PaintBorder") {
 474                         c = currentControls.elementAt(0);
 475                         if(c instanceof AbstractButton) {
 476                             for(int i = 0; i < currentControls.size(); i++) {
 477                                 b = (AbstractButton) currentControls.elementAt(i);
 478                                 b.setBorderPainted(cb.isSelected());
 479                                 b.invalidate();
 480                             }
 481                         }
 482                     } else if(command == "PaintFocus") {
 483                         c = currentControls.elementAt(0);
 484                         if(c instanceof AbstractButton) {
 485                             for(int i = 0; i < currentControls.size(); i++) {
 486                                 b = (AbstractButton) currentControls.elementAt(i);
 487                                 b.setFocusPainted(cb.isSelected());
 488                                 b.invalidate();
 489                             }
 490                         }
 491                     } else if(command == "ContentFilled") {
 492                         c = currentControls.elementAt(0);
 493                         if(c instanceof AbstractButton) {
 494                             for(int i = 0; i < currentControls.size(); i++) {
 495                                 b = (AbstractButton) currentControls.elementAt(i);
 496                                 b.setContentAreaFilled(cb.isSelected());
 497                                 b.invalidate();
 498                             }
 499                         }
 500                     }
 501                     invalidate();
 502                     validate();
 503                     repaint();
 504                 }
 505         };
 506 
 507         buttonPadListener = new ItemListener() {
 508                 Component c;
 509                 AbstractButton b;
 510 
 511                 public void itemStateChanged(ItemEvent e) {
 512                     // *** pad = 0


 532                     invalidate();
 533                     validate();
 534                     repaint();
 535                 }
 536         };
 537     }
 538 
 539     public void stateChanged(ChangeEvent e) {
 540         SingleSelectionModel model = (SingleSelectionModel) e.getSource();
 541         if(model.getSelectedIndex() == 0) {
 542             currentControls = buttons;
 543         } else if(model.getSelectedIndex() == 1) {
 544             currentControls = radiobuttons;
 545         } else if(model.getSelectedIndex() == 2) {
 546             currentControls = checkboxes;
 547         } else {
 548             currentControls = togglebuttons;
 549         }
 550     }
 551 
 552     public Vector<Component> getCurrentControls() {
 553         return currentControls;
 554     }
 555 }
< prev index next >