// swing.es // // FESI examples - JM Lugrin - 1998 // // This example demonstrates how you can play with the swing // toolkit with the FESI EcmaScript interpreter. // Requires: JavaAccess, Swing-1.0 // Adapt swingev.bat to run this example // First define some shortcuts - note that partially expanded // package names can be assigned. Swing = Packages.com.sun.java.swing; // Just change this line if it moves JFrame = Swing.JFrame; JButton = Swing.JButton; JRadioButton = Swing.JRadioButton; ButtonGroup = Swing.ButtonGroup; JPanel = Swing.JPanel; UIManager = Swing.UIManager; SwingUtilities = Swing.SwingUtilities; // As there is no exception handling in EcmaScript, there // will be an error if the look and feel is not on the classpath metalClassName = "com.sun.java.swing.plaf.metal.MetalLookAndFeel" motifClassName = "com.sun.java.swing.plaf.motif.MotifLookAndFeel" windowsClassName = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel" UIManager.setLookAndFeel(metalClassName); // Create the panel and its content panel = new JPanel(); button = new JButton("Hello, world"); button.setToolTipText("This is a Button with Text"); button.setMnemonic('h'); //for looks only; button does nada metalButton = new JRadioButton("Metal"); metalButton.setMnemonic('o'); // String of length 1 are considered as char windowsButton = new JRadioButton("Windows"); windowsButton.setMnemonic('w'); motifButton = new JRadioButton("Motif"); motifButton.setMnemonic('m'); // Group the radio buttons. group = new ButtonGroup(); group.add(metalButton); group.add(windowsButton); group.add(motifButton); panel.add(button); panel.add(metalButton); panel.add(windowsButton); panel.add(motifButton); // Now create the frame frame = new JFrame("Show swing"); frame.getContentPane().add("Center", panel); frame.pack(); frame.setVisible(true); frame.onWindowClosing = "frame.dispose();exit();"; metalButton.onAction = "setLF(metalClassName);"; motifButton.onAction = "setLF(motifClassName);"; windowsButton.onAction = "setLF(windowsClassName);"; function setLF(lf) { UIManager.setLookAndFeel(lf); SwingUtilities.updateComponentTreeUI(frame); frame.pack(); }