⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frame1.java~3~

📁 自己在学习过程中写的
💻 JAVA~3~
字号:
package frame1;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2008</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */


public class Frame1 extends Applet {
    boolean isStandalone = false;
    BorderLayout borderLayout1 = new BorderLayout();

    //Get a parameter value
    public String getParameter(String key, String def) {
        return isStandalone ? System.getProperty(key, def) :
                (getParameter(key) != null ? getParameter(key) : def);
    }

    //Construct the applet
    //public Frame1() {
    //}
    public class StyleChooser extends JPanel {
     JFrame frame;
     String metal= "Metal";
     String metalClassName = "javax.swing.plaf.metal.MetalLookAndFeel";

     String motif = "Motif";
     String motifClassName =
            "com.sun.java.swing.plaf.motif.MotifLookAndFeel";

     String windows = "Windows";
    String windowsClassName =
            "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";

    JRadioButton metalButton, motifButton, windowsButton;

    public StyleChooser() {
        // 建立一个提示标签
        JLabel label = new JLabel("Try the styles Swing has");

        metalButton = new JRadioButton(metal);
        metalButton.setMnemonic('o');
        metalButton.setActionCommand(metalClassName);

        motifButton = new JRadioButton(motif);
        motifButton.setMnemonic('m');
        motifButton.setActionCommand(motifClassName);

        windowsButton = new JRadioButton(windows);
        windowsButton.setMnemonic('w');
        windowsButton.setActionCommand(windowsClassName);

        // 将RadioButton归为同一组
        ButtonGroup group = new ButtonGroup();
        group.add(metalButton);
        group.add(motifButton);
        group.add(windowsButton);

        // Register a listener for the radio buttons.
        RadioListener myListener = new RadioListener();
        metalButton.addActionListener(myListener);
        motifButton.addActionListener(myListener);
        windowsButton.addActionListener(myListener);

        add(label);
        add(metalButton);
        add(motifButton);
        add(windowsButton);
    }

    //加入一个事件监听器处理选择RadioButton事件
    class RadioListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            String lnfName = e.getActionCommand();

            try {
                UIManager.setLookAndFeel(lnfName);
                SwingUtilities.updateComponentTreeUI(frame);
                frame.pack();
            }
            catch (Exception exc) {
                JRadioButton button = (JRadioButton)e.getSource();
                button.setEnabled(false);
                updateState();
                System.err.println("Could not load LookAndFeel: " + lnfName);
            }

        }
    }

    public void updateState() {
         String lnfName = UIManager.getLookAndFeel().getClass().getName();
         if (lnfName.indexOf(metal) >= 0) {
             metalButton.setSelected(true);
         } else if (lnfName.indexOf(windows) >= 0) {
             windowsButton.setSelected(true);
         } else if (lnfName.indexOf(motif) >= 0) {
             motifButton.setSelected(true);
         } else {
             System.err.println("StyleChooser is using an unknown L&F: " + lnfName);
         }
    }

    public static void main(String s[]) {
       // StyleChooser panel = new StyleChooser();
              //  frame = new JFrame("StyleChooser");
        //frame.addWindowListener(new WindowAdapter() {
        //    public void windowClosing(WindowEvent e) {System.exit(0);}
       // });
        //frame.getContentPane().add("Center", panel);
        //frame.pack();
        //frame.setVisible(true);

       // panel.updateState();
    }
}


    //Initialize the applet
    public void init() {
        try {
            jbInit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //Component initialization
    private void jbInit() throws Exception {
    }

    //Get Applet information
    public String getAppletInfo() {
        return "Applet Information";
    }

    //Get parameter info
    public String[][] getParameterInfo() {
        return null;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -