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

📄 mainwindow.java

📁 java实现浏览器等本地桌面的功能
💻 JAVA
字号:
/* * MainWindow.java * * Created on April 5, 2005, 8:51 AM */package org.jdesktop.demo;import com.jgoodies.looks.HeaderStyle;import com.jgoodies.looks.Options;import com.jgoodies.looks.plastic.PlasticLookAndFeel;import com.jgoodies.looks.plastic.PlasticTheme;import java.awt.EventQueue;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import javax.swing.JFrame;import javax.swing.JMenu;import javax.swing.UIManager;import javax.swing.plaf.metal.MetalLookAndFeel;import javax.swing.plaf.metal.MetalTheme;import org.jdesktop.swingx.util.WindowUtils;/** * * @author  rbair */public class MainWindow extends javax.swing.JFrame {    private DemoPanel demo;    private SourceBrowserWindow sourceWindow;        /**     * Creates new form MainWindow      */    public MainWindow(DemoPanel demo) {        this.demo = demo;        sourceWindow = new SourceBrowserWindow(demo.getSourceRootDir());        sourceWindow.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);        initComponents();        demo.addMenuItems(menuBar);        setContentPane(demo.getContent());        setSize(800, 600);        setLocation(WindowUtils.getPointForCentering(this));        menuBar.putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH);    }        /** This method is called from within the constructor to     * initialize the form.     * WARNING: Do NOT modify this code. The content of this method is     * always regenerated by the Form Editor.     */    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents    private void initComponents() {        javax.swing.JSeparator jSeparator1;        menuBar = new javax.swing.JMenuBar();        menu = new javax.swing.JMenu();        menuViewSourceMI = new javax.swing.JMenuItem();        jSeparator1 = new javax.swing.JSeparator();        menuExitMI = new javax.swing.JMenuItem();        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);        menu.setText("Menu");        menu.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                menuActionPerformed(evt);            }        });        menuViewSourceMI.setText("View Source...");        menuViewSourceMI.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                menuViewSourceMIActionPerformed(evt);            }        });        menu.add(menuViewSourceMI);        menu.add(jSeparator1);        menuExitMI.setText("Exit");        menuExitMI.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                menuExitMIActionPerformed(evt);            }        });        menu.add(menuExitMI);        menuBar.add(menu);        setJMenuBar(menuBar);        pack();    }    // </editor-fold>//GEN-END:initComponents    private void menuExitMIActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuExitMIActionPerformed        System.exit(0);    }//GEN-LAST:event_menuExitMIActionPerformed    private void menuViewSourceMIActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuViewSourceMIActionPerformed        //open up the SourceBrowserWindow, non-modally. Load it with the source        //files for the currently running demo.        sourceWindow.setSelectedSourceFile(demo.getSourceFile());        if (!sourceWindow.isVisible()) {            sourceWindow.setTitle(getTitle() + " Source Browser");            sourceWindow.setLocation(WindowUtils.getPointForStaggering(this));            sourceWindow.setVisible(true);        } else {            sourceWindow.toFront();        }    }//GEN-LAST:event_menuViewSourceMIActionPerformed    private void menuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuActionPerformed// TODO add your handling code here:    }//GEN-LAST:event_menuActionPerformed        // Variables declaration - do not modify//GEN-BEGIN:variables    private javax.swing.JMenu menu;    private javax.swing.JMenuBar menuBar;    private javax.swing.JMenuItem menuExitMI;    private javax.swing.JMenuItem menuViewSourceMI;    // End of variables declaration//GEN-END:variables        /**     * Mapping of all of the THEMES currently supported.  These are PlasticLookAndFeel themes.     */    private static Map<String,MetalTheme> THEMES = null;    public static void main(String[] args) {    	CmdLineParser parser = new CmdLineParser();    	CmdLineParser.Option dOption = parser.addStringOption('d', "Demo");    	try {    		parser.parse(args);    	} catch (CmdLineParser.UnknownOptionException ex) {    		ex.printStackTrace();    		printUsage();    		System.exit(1);    	} catch (CmdLineParser.IllegalOptionValueException ex) {    		ex.printStackTrace();    		printUsage();    		System.exit(2);    	}    	//look for the -d argument    	final String demoClassName = (String)parser.getOptionValue(dOption);    	    	setAppLookAndFeel();        EventQueue.invokeLater(new Runnable() {            public void run() {                try {                    DemoPanel demo = (DemoPanel)Class.forName(demoClassName).newInstance();                    MainWindow mainWindow = new MainWindow(demo);                    mainWindow.setTitle(demo.getName());                    mainWindow.setVisible(true);                } catch (Exception e) {                    System.err.println("Failed to find, create, and open the MainWindow. " +            				"The Demo class was '" + demoClassName + "'");                    e.printStackTrace();                    printUsage();                    System.exit(3);            	}            }        });    }        private static void printUsage() {    	System.out.println("Pass in the name of the JFrame that is to be the main window " +    			"for this app, like so:\n" +    			"-w org.jdesktop.binding.demo.blar.BlarWindow");    }    /**     * Sets the application look and feel.  Currently, the look and feel and theme      * can be changed on the command line by the command line properties     * "org.jdesktop.demo.BindingDemo.LookAndFeel" and "org.jdesktop.demo.BindingDemo.Theme".     */    private static void setAppLookAndFeel() {		//set the look and feel for the app		try {	        //initialize the THEMES map if they have not already been so initialized	        if (THEMES == null) {	                initThemes();	        }	        //The defaultClassName and defaultThemeName are the look and feel class name and theme name to use if no system property	        //has been set.	        String defaultClassName = "com.jgoodies.looks.plastic.PlasticXPLookAndFeel";	        String defaultThemeName = "com.jgoodies.looks.plastic.theme.ExperienceBlue";	        String className = defaultClassName;	        String themeName = defaultThemeName;            try {                System.getProperty("org.jdesktop.demo.Theme", defaultThemeName);                System.getProperty("org.jdesktop.demo.LookAndFeel", defaultClassName);            } catch (Throwable e) {                //didn't work, oh well.            }		        //set the current plasic look and feel theme, and the current look and feel	        //Object theme = THEMES.get(themeName);                Object theme = null;	        if (theme == null) {	                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());	        } else if (theme instanceof PlasticTheme){	                PlasticLookAndFeel.setMyCurrentTheme((PlasticTheme)THEMES.get(themeName));	                UIManager.setLookAndFeel(className);	        } else if (theme instanceof MetalTheme) {	                MetalLookAndFeel.setCurrentTheme((MetalTheme)THEMES.get(themeName));	                UIManager.setLookAndFeel(className);	        }	        		        		} catch (Exception e) {		        e.printStackTrace();		}                }        /**     * Initializes the THEMES map.     */    private static void initThemes() {            THEMES = new HashMap<String,MetalTheme>();            List list = PlasticLookAndFeel.getInstalledThemes();            for (Iterator itr = list.iterator(); itr.hasNext();) {                    PlasticTheme element = (PlasticTheme) itr.next();                    THEMES.put(element.getClass().getName(), element);            }            //add the normal swing themes            THEMES.put("javax.swing.plaf.metal.DefaultMetalTheme", new javax.swing.plaf.metal.DefaultMetalTheme());            THEMES.put("javax.swing.plaf.metal.OceanTheme", new javax.swing.plaf.metal.OceanTheme());    }}

⌨️ 快捷键说明

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