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

📄 webpad.java

📁 编写程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * @(#)WebPad.java	1.5 03/12/19 *  * Copyright (c) 2004 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. */import java.awt.*;import java.awt.event.*;import java.util.Enumeration;import java.util.Vector;import javax.swing.*;import javax.jnlp.BasicService;import javax.jnlp.ServiceManager;import javax.jnlp.PersistenceService;import javax.jnlp.UnavailableServiceException;import javax.jnlp.FileContents;import java.io.*;import java.net.*;/** * Demonstrates the JLF Actions classes. * * - The actions use the JLF icons, text and mnemonics. * - Actions are shared between the JToolBar and JMenuBar. * - if an Action is enabled/disabled then it will be disabled in both places. * - When a mouse is over a toolbar button or a menu item, then the long *   description of that action will be displayed in the status bar. * - Abstracts the actionPerformed method from the Action class to a handler. * * */public class WebPad extends JFrame implements ActionListener {        // These are the actions defined for the application    private AboutAction aboutAction;    private CutAction cutAction;    private CopyAction copyAction;    private PasteAction pasteAction;    private OpenAction openAction;    private SaveAction saveAction;    private SaveAsAction saveAsAction;    private PrintAction printAction;    private HelpAction helpAction;    private ExitAction exitAction;    private PublishAction publishAction;    private ShowAction showAction;    private ClassLoader cl;        // Vector for holding all the actions.    private Vector actions;        // Status bar    private JLabel status;        // Text area which acts as a clipboard.    private JTextArea textArea;        // This adapter handles Mouse over messages on toolbar buttons and    // menu items.    private MouseHandler mouseHandler;        // Popup Menu with the actions.    private JPopupMenu popup;       private PersistenceService ps;    private BasicService bs;    private FileContents fc;     public WebPad() {        super("WebPad");        cl = this.getClass().getClassLoader();        initActions();                status = createStatusBar();        mouseHandler = new MouseHandler(status);                setJMenuBar(createMenu());        getContentPane().add(createToolBar(), BorderLayout.NORTH);        getContentPane().add(createPanel(), BorderLayout.CENTER);        getContentPane().add(status, BorderLayout.SOUTH);                popup = createPopupMenu();                initPersistence();        addWindowListener(new WindowAdapter()  {		    public void windowClosing(WindowEvent evt)  {			System.exit(0);		    }		});            }        // This method should be called before creating the UI    // to create all the Actions    private void initActions()  {        actions = new Vector();                aboutAction = new AboutAction();        registerAction(aboutAction);                cutAction = new CutAction();        registerAction(cutAction);                copyAction = new CopyAction();        registerAction(copyAction);                pasteAction = new PasteAction();        registerAction(pasteAction);		        openAction = new OpenAction();	registerAction(openAction);		saveAction = new SaveAction();	registerAction(saveAction);		saveAsAction = new SaveAsAction();	registerAction(saveAsAction);                printAction = new PrintAction();        registerAction(printAction);		exitAction = new ExitAction();	registerAction(exitAction);		helpAction = new HelpAction();	registerAction(helpAction);		publishAction = new PublishAction();	registerAction(publishAction);		showAction = new ShowAction();	registerAction(showAction);    }        private void registerAction(JLFAbstractAction action)  {        action.addActionListener(this);        actions.addElement(action);    }        // Creates the application menu bar.    private JMenuBar createMenu()  {        JMenuBar menuBar = new JMenuBar();	        JMenuItem menuItem;	        // Build the File menu        JMenu fileMenu = new JMenu("File");        fileMenu.setMnemonic('F');	if (FileHandler.isEnabled()) {	    menuItem = fileMenu.add(openAction);	    menuItem.addMouseListener(mouseHandler);	    menuItem = fileMenu.add(saveAction);	    menuItem.addMouseListener(mouseHandler);	    menuItem = fileMenu.add(saveAsAction);	    menuItem.addMouseListener(mouseHandler);	    menuItem = fileMenu.add(printAction);	    menuItem.addMouseListener(mouseHandler);	    fileMenu.add(new JSeparator());	}	menuItem = fileMenu.add(exitAction);	menuItem.addMouseListener(mouseHandler);	        // Build the edit menu        JMenu editMenu = new JMenu("Edit");        editMenu.setMnemonic('E');        menuItem = editMenu.add(cutAction);        menuItem.addMouseListener(mouseHandler);        menuItem = editMenu.add(copyAction);        menuItem.addMouseListener(mouseHandler);        menuItem = editMenu.add(pasteAction);        menuItem.addMouseListener(mouseHandler);		// Build the help menu	JMenu helpMenu = new JMenu("Help");	helpMenu.setMnemonic('H');	menuItem = helpMenu.add(helpAction);        menuItem.addMouseListener(mouseHandler);        menuItem = helpMenu.add(aboutAction);        menuItem.addMouseListener(mouseHandler);	        menuBar.add(fileMenu);        menuBar.add(editMenu);	if (WebHandler.isEnabled()) {	    JMenu webMenu = new JMenu("Web");	    webMenu.setMnemonic('W');	    menuItem = webMenu.add(publishAction);	    menuItem.addMouseListener(mouseHandler);	    menuItem = webMenu.add(showAction);	    menuItem.addMouseListener(mouseHandler);	    menuBar.add(webMenu);	}	menuBar.add(helpMenu);                return menuBar;    }        private JToolBar createToolBar()  {        JToolBar toolbar = new JToolBar();                JButton button;                button = toolbar.add(cutAction);        button.addMouseListener(mouseHandler);        button = toolbar.add(copyAction);        button.addMouseListener(mouseHandler);        button = toolbar.add(pasteAction);        button.addMouseListener(mouseHandler);        toolbar.addSeparator();        button = toolbar.add(aboutAction);        button.addMouseListener(mouseHandler);	        return toolbar;    }        private JPopupMenu createPopupMenu()  {        JPopupMenu menu = new JPopupMenu();                JMenuItem menuItem;                menuItem = menu.add(cutAction);        menuItem.addMouseListener(mouseHandler);        menuItem = menu.add(copyAction);        menuItem.addMouseListener(mouseHandler);        menuItem = menu.add(pasteAction);        menuItem.addMouseListener(mouseHandler);        menu.addSeparator();        menuItem = menu.add(aboutAction);        menuItem.addMouseListener(mouseHandler);

⌨️ 快捷键说明

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