/* * @(#)SimpleExample.java 1.8 97/10/15 * * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved. * * This software is the confidential and proprietary information of Sun * Microsystems, Inc. ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into * with Sun. * * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING * THIS SOFTWARE OR ITS DERIVATIVES. * */ import java.applet.Applet; import java.awt.*; import java.awt.event.*; import com.sun.java.swing.*; /** * An application that displays a JButton and two JRadioButtons. * The JRadioButtons determine the look and feel used by the application. */ public class SimpleExample extends JPanel { static JFrame frame; static String basic = new String("Basic"); static String rose = new String("Rose"); public SimpleExample() { super(true); // Create the buttons. JButton button = new JButton("Hello, world"); button.setKeyAccelerator('h'); //for looks only; button does nada JRadioButton basicButton = new JRadioButton(basic); basicButton.setKeyAccelerator('b'); basicButton.setActionCommand(basic); basicButton.setSelected(true); JRadioButton roseButton = new JRadioButton(rose); roseButton.setKeyAccelerator('r'); roseButton.setActionCommand(rose); // Group the radio buttons. ButtonGroup group = new ButtonGroup(); group.add(basicButton); group.add(roseButton); // Register a listener for the radio buttons. RadioListener myListener = new RadioListener(); roseButton.addActionListener(myListener); basicButton.addActionListener(myListener); add(button); add(basicButton); add(roseButton); } /** An ActionListener that listens to the radio buttons. */ class RadioListener implements ActionListener { public void actionPerformed(ActionEvent e) { String lnfName = null; if (e.getActionCommand() == rose) { lnfName = "com.sun.java.swing.rose.RoseLookAndFeel"; } else { lnfName = "com.sun.java.swing.basic.BasicLookAndFeel"; } try { UIManager.setLookAndFeel(lnfName); SwingUtilities.updateComponentTreeUI(frame); frame.pack(); } catch (Exception exc) { System.err.println("could not load LookAndFeel: " + lnfName); } } } public static void main(String s[]) { WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) {System.exit(0);} }; frame = new JFrame("SimpleExample"); frame.addWindowListener(l); frame.add("Center", new SimpleExample()); frame.pack(); frame.setVisible(true); } }