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

📄 thumbelinaframe.java

📁 html 解析处理代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        int bordery;        tk = getToolkit ();        dim = tk.getScreenSize ();        borderx = dim.width * BORDERPERCENT / 100;        bordery = dim.height * BORDERPERCENT / 100;        setBounds (            borderx,            bordery,            dim.width - (2 * borderx),            dim.height - (2 * bordery));    }    /**     * Restores the window size based on stored preferences.     * If no preferences exist, it calls <code>initSize()</code>.     */    public void restoreSize ()    {        Preferences prefs;        String size;        Rectangle rectangle;        prefs = Preferences.userNodeForPackage (getClass ());        size = prefs.get (FRAMESIZE, "");        if ("".equals (size))            initSize ();        else            try            {                rectangle = fromString (size);                if (rational (rectangle))                    setBounds (                        rectangle.x,                        rectangle.y,                        rectangle.width,                        rectangle.height);                else                    initSize ();            }            catch (IllegalArgumentException iae)            {                initSize ();            }    }    /**     * Converts the rectangle to a string.     * The rectangle is converted into a string that is of the form     * <pre>     * [x,y,width,height].     * </pre>     * @return The string equivalent of the rectangle.     * @param r The rectangle containing the window position and size,     * as returned by <code>getBounds()</code>.     */    protected String toString (final Rectangle r)    {        return ("[" + r.x + "," + r.y + "," + r.width + "," + r.height + "]");    }    /**     * Convert the given string to a valid rectangle.     * The string is converted to a Rectangle.     * @param value The value to parse.     * @exception IllegalArgumentException if the format does not match the     * form "[x,y,width,height]" with all values integers.     * @return Returns the rectangle extracted from the string.     */    protected Rectangle fromString (final String value)        throws            IllegalArgumentException    {        String guts;        int current;        int[] values;        int index;        Rectangle ret;        try        {            // parse "[x,y,width,height]"            if (value.startsWith ("[") && value.endsWith ("]"))            {                guts = value.substring (1, value.length () - 1) + ",";                current = 0;                values = new int[4];                for (int i = 0; i < 4; i++)                {                    index = guts.indexOf (",", current);                    if (-1 == index)                        throw new IllegalArgumentException (                            "invalid format \"" + value + "\"");                    else                    {                        values[i] = Integer.parseInt (                            guts.substring (current, index));                        current = index + 1;                    }                }                ret = new Rectangle (                    values[0], values[1], values[2], values[3]);            }            else                throw new IllegalArgumentException (                    "invalid format \"" + value + "\"");        }        catch (NumberFormatException nfe)        {            throw new IllegalArgumentException (nfe.getMessage ());        }        return (ret);    }    /**     * Check if the rectangle represents a valid screen position and size.     * @param r The rectangle to check.     * @return <code>true</code> if this could be a valid frame bounds.     */    private boolean rational (final Rectangle r)    {        Toolkit tk;        Dimension winsize;        tk = getToolkit ();        winsize = tk.getScreenSize();        // all elements must be not stupid w.r.t. the screen size        // we assume here that that means no more than 10% off screen        // on the left, right and bottom sides        return (   (r.x >= r.width / -10)                && (r.y >= 0)                && (r.width > 0)                && (r.height > 0)                && (r.x + r.width <= winsize.width + r.width / 10)                && (r.y + r.height <= winsize.height + r.height / 10));    }    /**     * Create the menu.     * Initializes the menu and adds it to the frame.     */    public void makeMenu ()    {        mMenu = new JMenuBar ();        mURL = new JMenu ();        mOpen = new JMenuItem ();        mGoogle = new JMenuItem ();        mSeparator1 = new JSeparator ();        mSeparator2 = new JSeparator ();        mExit = new JMenuItem ();        mView = new JMenu ();        mStatusVisible = new JCheckBoxMenuItem ();        mHistoryVisible = new JCheckBoxMenuItem ();        mHelp = new JMenu ();        mAbout = new JMenuItem ();        mCommand = new JMenu ();        mReset = new JMenuItem ();        mClear = new JMenuItem ();        mURL.setMnemonic ('U');        mURL.setText ("URL");        mOpen.setMnemonic ('O');        mOpen.setText ("Open");        mOpen.setToolTipText ("Open a URL.");        mURL.add (mOpen);        mGoogle.setMnemonic ('G');        mGoogle.setText ("Google");        mGoogle.setToolTipText ("Search Google.");        mURL.add (mGoogle);        mURL.add (mSeparator1);        mURL.add (mSeparator2);        mExit.setMnemonic ('E');        mExit.setText ("Exit");        mExit.setToolTipText ("Quit Thumbelina.");        mURL.add (mExit);        mMenu.add (mURL);        mView.setMnemonic ('V');        mView.setText ("View");        mStatusVisible.setMnemonic ('S');        mStatusVisible.setSelected (getThumbelina ().getStatusBarVisible ());        mStatusVisible.setText ("Status Bar");        mStatusVisible.setToolTipText ("Show/Hide the status bar.");        mView.add (mStatusVisible);        mHistoryVisible.setMnemonic ('H');        mHistoryVisible.setSelected (getThumbelina ().getHistoryListVisible ());        mHistoryVisible.setText ("History List");        mHistoryVisible.setToolTipText ("Show/Hide the history list.");        mView.add (mHistoryVisible);        mMenu.add (mView);        mCommand.setMnemonic ('C');        mCommand.setText ("Command");        mReset.setMnemonic ('R');        mReset.setText ("Reset");        mReset.setToolTipText ("Reset Thumbelina.");        mClear.setMnemonic ('L');        mClear.setText ("Clear");        mClear.setToolTipText ("Clear display.");        mCommand.add (mReset);        mCommand.add (mClear);        mCommand.add (mHelp);        mMenu.add (mCommand);        mHelp.setMnemonic ('H');        mHelp.setText ("Help");        mAbout.setMnemonic ('A');        mAbout.setText ("About");        mAbout.setToolTipText ("Information about Thumbelina.");        mHelp.add (mAbout);        mMenu.add (mHelp);        mOpen.addActionListener (this);        mGoogle.addActionListener (this);        mExit.addActionListener (this);        mStatusVisible.addItemListener (this);        mHistoryVisible.addItemListener (this);        mReset.addActionListener (this);        mClear.addActionListener (this);        mAbout.addActionListener (this);    }    /**     * Adjusts the menu, by inserting the current MRU list.     * Removes the old MRU (Most Recently Used) items and inserts new     * ones betweeen the two separators.     */    public void updateMenu ()    {        Preferences prefs;        int start;        int end;        Component component;        JMenuItem item;        int count;        String string;        prefs = Preferences.userNodeForPackage (getClass ());        start = -1;        end = -1;        for (int i = 0; i < mURL.getItemCount (); i++)        {            component = mURL.getMenuComponent (i);            if (component == mSeparator1)                start = i + 1;            else if (component == mSeparator2)                end = i;        }        if ((-1 != start) && (-1 != end))        {            for (int i = start; i < end; i++)                mURL.remove (start);            count = prefs.getInt (MRULENGTH, 0);            for (int i = 0; i < count; i++)            {                string = prefs.get (MRUPREFIX + i, "");                if (!"".equals (string))                {                    item = new JMenuItem ();                    item.setActionCommand (string);                    if (string.length () > 40)                        string = string.substring (0, 38) + "...";                    item.setText (string);                    item.addActionListener (this);                    mURL.add (item, start++);                }            }        }    }    //    // WindowListener interface    //    /**     * Invoked the first time a window is made visible.     * <i>Not used.</i>     * @param event The window event.     */    public void windowOpened (final WindowEvent event)    {    }    /**     * Handles window closing event.     * Performs function <code>exitApplication()</code>.     * @param event The window event.     */    public void windowClosing (final WindowEvent event)    {        exit ();    }    /**     * Invoked when a window has been closed as the result     * of calling dispose on the window.     * <i>Not used.</i>     * @param event The window event.     */    public void windowClosed (final WindowEvent event)    {    }    /**     * Invoked when a window is changed from a normal to a     * minimized state. For many platforms, a minimized window     * is displayed as the icon specified in the window's     * iconImage property.     * <i>Not used.</i>     * @param event The window event.     */    public void windowIconified (final WindowEvent event)    {    }    /**     * Invoked when a window is changed from a minimized     * to a normal state.     * <i>Not used.</i>     * @param event The window event.     */    public void windowDeiconified (final WindowEvent event)    {    }    /**     * Invoked when the window is set to be the user's     * active window, which means the window (or one of its     * subcomponents) will receive keyboard events.     * <i>Not used.</i>     * @param event The window event.     */    public void windowActivated (final WindowEvent event)    {    }    /**     * Invoked when a window is no longer the user's active     * window, which means that keyboard events will no longer     * be delivered to the window or its subcomponents.     * <i>Not used.</i>     * @param event The window event.     */    public void windowDeactivated (final WindowEvent event)    {    }    //    // ActionListener interface    //    /**     * Handles events from the menu.

⌨️ 快捷键说明

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