home *** CD-ROM | disk | FTP | other *** search
/ Australian PC Authority 1999 May / may1999.iso / May / JBUILDER / JSAMPLES.Z / SimpleExample.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-30  |  3.1 KB  |  71 lines

  1. import com.sun.java.swing.AbstractButton;
  2. import com.sun.java.swing.ButtonGroup;
  3. import com.sun.java.swing.JButton;
  4. import com.sun.java.swing.JFrame;
  5. import com.sun.java.swing.JPanel;
  6. import com.sun.java.swing.JRadioButton;
  7. import com.sun.java.swing.UIManager;
  8. import java.awt.Container;
  9.  
  10. public class SimpleExample extends JPanel {
  11.    static JFrame frame;
  12.    static String metal = "Metal";
  13.    static String metalClassName = "com.sun.java.swing.plaf.metal.MetalLookAndFeel";
  14.    static String motif = "Motif";
  15.    static String motifClassName = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
  16.    static String windows = "Windows";
  17.    static String windowsClassName = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
  18.    JRadioButton metalButton;
  19.    JRadioButton motifButton;
  20.    JRadioButton windowsButton;
  21.  
  22.    public SimpleExample() {
  23.       JButton var1 = new JButton("Hello, world");
  24.       ((AbstractButton)var1).setMnemonic('h');
  25.       this.metalButton = new JRadioButton(metal);
  26.       this.metalButton.setMnemonic('o');
  27.       this.metalButton.setActionCommand(metalClassName);
  28.       this.motifButton = new JRadioButton(motif);
  29.       this.motifButton.setMnemonic('m');
  30.       this.motifButton.setActionCommand(motifClassName);
  31.       this.windowsButton = new JRadioButton(windows);
  32.       this.windowsButton.setMnemonic('w');
  33.       this.windowsButton.setActionCommand(windowsClassName);
  34.       ButtonGroup var2 = new ButtonGroup();
  35.       var2.add(this.metalButton);
  36.       var2.add(this.motifButton);
  37.       var2.add(this.windowsButton);
  38.       SimpleExample$RadioListener var3 = new SimpleExample$RadioListener(this);
  39.       this.metalButton.addActionListener(var3);
  40.       this.motifButton.addActionListener(var3);
  41.       this.windowsButton.addActionListener(var3);
  42.       ((Container)this).add(var1);
  43.       ((Container)this).add(this.metalButton);
  44.       ((Container)this).add(this.motifButton);
  45.       ((Container)this).add(this.windowsButton);
  46.    }
  47.  
  48.    public void updateState() {
  49.       String var1 = UIManager.getLookAndFeel().getClass().getName();
  50.       if (var1.indexOf(metal) >= 0) {
  51.          this.metalButton.setSelected(true);
  52.       } else if (var1.indexOf(windows) >= 0) {
  53.          this.windowsButton.setSelected(true);
  54.       } else if (var1.indexOf(motif) >= 0) {
  55.          this.motifButton.setSelected(true);
  56.       } else {
  57.          System.err.println("SimpleExample if using an unknown L&F: " + var1);
  58.       }
  59.    }
  60.  
  61.    public static void main(String[] var0) {
  62.       SimpleExample var1 = new SimpleExample();
  63.       frame = new JFrame("SimpleExample");
  64.       frame.addWindowListener(new SimpleExample$1());
  65.       frame.getContentPane().add("Center", var1);
  66.       frame.pack();
  67.       frame.setVisible(true);
  68.       var1.updateState();
  69.    }
  70. }
  71.