swingset2.java
来自「一个小公司要求给写的很简单的任务管理系统。」· Java 代码 · 共 1,408 行 · 第 1/4 页
JAVA
1,408 行
/* * @(#)SwingSet2.java 1.54 06/05/31 * * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * -Redistribution of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * -Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of Sun Microsystems, Inc. or the names of contributors may * be used to endorse or promote products derived from this software without * specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed, licensed or intended * for use in the design, construction, operation or maintenance of any * nuclear facility. *//* * @(#)SwingSet2.java 1.54 06/05/31 */import javax.swing.*;import javax.swing.event.*;import javax.swing.text.*;import javax.swing.border.*;import javax.swing.colorchooser.*;import javax.swing.filechooser.*;import javax.accessibility.*;import javax.swing.plaf.metal.MetalTheme;import javax.swing.plaf.metal.OceanTheme;import javax.swing.plaf.metal.DefaultMetalTheme;import javax.swing.plaf.metal.MetalLookAndFeel;import java.lang.reflect.*;import java.awt.*;import java.awt.event.*;import java.beans.*;import java.util.*;import java.io.*;import java.applet.*;import java.net.*;/** * A demo that shows all of the Swing components. * * @version 1.54 05/31/06 * @author Jeff Dinkins */public class SwingSet2 extends JPanel { String[] demos = { "ButtonDemo", "ColorChooserDemo", "ComboBoxDemo", "FileChooserDemo", "HtmlDemo", "ListDemo", "OptionPaneDemo", "ProgressBarDemo", "ScrollPaneDemo", "SliderDemo", "SplitPaneDemo", "TabbedPaneDemo", "TableDemo", "ToolTipDemo", "TreeDemo" }; void loadDemos() { for(int i = 0; i < demos.length;) { if(isApplet() && demos[i].equals("FileChooserDemo")) { // don't load the file chooser demo if we are // an applet } else { loadDemo(demos[i]); } i++; } } // Possible Look & Feels private static final String mac = "com.sun.java.swing.plaf.mac.MacLookAndFeel"; private static final String metal = "javax.swing.plaf.metal.MetalLookAndFeel"; private static final String motif = "com.sun.java.swing.plaf.motif.MotifLookAndFeel"; private static final String windows = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"; private static final String gtk = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel"; // The current Look & Feel private static String currentLookAndFeel = metal; // List of demos private ArrayList<DemoModule> demosList = new ArrayList<DemoModule>(); // The preferred size of the demo private static final int PREFERRED_WIDTH = 720; private static final int PREFERRED_HEIGHT = 640; // Box spacers private Dimension HGAP = new Dimension(1,5); private Dimension VGAP = new Dimension(5,1); // Resource bundle for internationalized and accessible text private ResourceBundle bundle = null; // A place to hold on to the visible demo private DemoModule currentDemo = null; private JPanel demoPanel = null; // About Box private JDialog aboutBox = null; // Status Bar private JTextField statusField = null; // Tool Bar private ToggleButtonToolBar toolbar = null; private ButtonGroup toolbarGroup = new ButtonGroup(); // Menus private JMenuBar menuBar = null; private JMenu lafMenu = null; private JMenu themesMenu = null; private JMenu audioMenu = null; private JMenu optionsMenu = null; private ButtonGroup lafMenuGroup = new ButtonGroup(); private ButtonGroup themesMenuGroup = new ButtonGroup(); private ButtonGroup audioMenuGroup = new ButtonGroup(); // Popup menu private JPopupMenu popupMenu = null; private ButtonGroup popupMenuGroup = new ButtonGroup(); // Used only if swingset is an application private JFrame frame = null; // Used only if swingset is an applet private SwingSet2Applet applet = null; // To debug or not to debug, that is the question private boolean DEBUG = true; private int debugCounter = 0; // The tab pane that holds the demo private JTabbedPane tabbedPane = null; private JEditorPane demoSrcPane = null; // contentPane cache, saved from the applet or application frame Container contentPane = null; // number of swingsets - for multiscreen // keep track of the number of SwingSets created - we only want to exit // the program when the last one has been closed. private static int numSSs = 0; private static Vector<SwingSet2> swingSets = new Vector<SwingSet2>(); private boolean dragEnabled = false; public SwingSet2(SwingSet2Applet applet) { this(applet, null); } /** * SwingSet2 Constructor */ public SwingSet2(SwingSet2Applet applet, GraphicsConfiguration gc) { // Note that applet may be null if this is started as an application this.applet = applet; if (!isApplet()) { frame = createFrame(gc); } // set the layout setLayout(new BorderLayout()); // set the preferred size of the demo setPreferredSize(new Dimension(PREFERRED_WIDTH,PREFERRED_HEIGHT)); initializeDemo(); preloadFirstDemo(); // Show the demo. Must do this on the GUI thread using invokeLater. SwingUtilities.invokeLater(new Runnable() { public void run() { showSwingSet2(); } }); // Start loading the rest of the demo in the background DemoLoadThread demoLoader = new DemoLoadThread(this); demoLoader.start(); } /** * SwingSet2 Main. Called only if we're an application, not an applet. */ public static void main(String[] args) { // Create SwingSet on the default monitor UIManager.put("swing.boldMetal", Boolean.FALSE); SwingSet2 swingset = new SwingSet2(null, GraphicsEnvironment. getLocalGraphicsEnvironment(). getDefaultScreenDevice(). getDefaultConfiguration()); } // ******************************************************* // *************** Demo Loading Methods ****************** // ******************************************************* public void initializeDemo() { JPanel top = new JPanel(); top.setLayout(new BorderLayout()); add(top, BorderLayout.NORTH); menuBar = createMenus(); if (isApplet()) { applet.setJMenuBar(menuBar); } else { frame.setJMenuBar(menuBar); } // creates popup menu accessible via keyboard popupMenu = createPopupMenu(); ToolBarPanel toolbarPanel = new ToolBarPanel(); toolbarPanel.setLayout(new BorderLayout()); toolbar = new ToggleButtonToolBar(); toolbarPanel.add(toolbar, BorderLayout.CENTER); top.add(toolbarPanel, BorderLayout.SOUTH); toolbarPanel.addContainerListener(toolbarPanel); tabbedPane = new JTabbedPane(); add(tabbedPane, BorderLayout.CENTER); tabbedPane.getModel().addChangeListener(new TabListener()); statusField = new JTextField(""); statusField.setEditable(false); add(statusField, BorderLayout.SOUTH); demoPanel = new JPanel(); demoPanel.setLayout(new BorderLayout()); demoPanel.setBorder(new EtchedBorder()); tabbedPane.addTab("Hi There!", demoPanel); // Add html src code viewer demoSrcPane = new JEditorPane("text/html", getString("SourceCode.loading")); demoSrcPane.setEditable(false); JScrollPane scroller = new JScrollPane(); scroller.getViewport().add(demoSrcPane); tabbedPane.addTab( getString("TabbedPane.src_label"), null, scroller, getString("TabbedPane.src_tooltip") ); } DemoModule currentTabDemo = null; class TabListener implements ChangeListener { public void stateChanged(ChangeEvent e) { SingleSelectionModel model = (SingleSelectionModel) e.getSource(); boolean srcSelected = model.getSelectedIndex() == 1; if(currentTabDemo != currentDemo && demoSrcPane != null && srcSelected) { demoSrcPane.setText(getString("SourceCode.loading")); repaint(); } if(currentTabDemo != currentDemo && srcSelected) { currentTabDemo = currentDemo; setSourceCode(currentDemo); } } } /** * Create menus */ public JMenuBar createMenus() { JMenuItem mi; // ***** create the menubar **** JMenuBar menuBar = new JMenuBar(); menuBar.getAccessibleContext().setAccessibleName( getString("MenuBar.accessible_description")); // ***** create File menu JMenu fileMenu = (JMenu) menuBar.add(new JMenu(getString("FileMenu.file_label"))); fileMenu.setMnemonic(getMnemonic("FileMenu.file_mnemonic")); fileMenu.getAccessibleContext().setAccessibleDescription(getString("FileMenu.accessible_description")); createMenuItem(fileMenu, "FileMenu.about_label", "FileMenu.about_mnemonic", "FileMenu.about_accessible_description", new AboutAction(this)); fileMenu.addSeparator(); createMenuItem(fileMenu, "FileMenu.open_label", "FileMenu.open_mnemonic", "FileMenu.open_accessible_description", null); createMenuItem(fileMenu, "FileMenu.save_label", "FileMenu.save_mnemonic", "FileMenu.save_accessible_description", null); createMenuItem(fileMenu, "FileMenu.save_as_label", "FileMenu.save_as_mnemonic", "FileMenu.save_as_accessible_description", null); if(!isApplet()) { fileMenu.addSeparator(); createMenuItem(fileMenu, "FileMenu.exit_label", "FileMenu.exit_mnemonic", "FileMenu.exit_accessible_description", new ExitAction(this) ); } // Create these menu items for the first SwingSet only. if (numSSs == 0) { // ***** create laf switcher menu lafMenu = (JMenu) menuBar.add(new JMenu(getString("LafMenu.laf_label"))); lafMenu.setMnemonic(getMnemonic("LafMenu.laf_mnemonic"));
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?