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

📄 window.java

📁 This is a resource based on j2me embedded,if you dont understand,you can connection with me .
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * @(#)Window.java	1.48 06/10/10 * * Copyright  1990-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER *  * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation.  *  * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt).  *  * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA  *  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions.  * */package java.awt;import java.awt.event.*;import java.util.Vector;import java.util.Locale;import java.util.EventListener;import java.io.Serializable;import java.io.ObjectOutputStream;import java.io.ObjectInputStream;import java.io.IOException;import java.io.OptionalDataException;import java.util.ResourceBundle;import java.util.Set;import java.lang.ref.WeakReference;import java.lang.reflect.InvocationTargetException;import java.security.AccessController;import java.util.EventListener;import java.awt.AWTEventMulticaster;import java.awt.im.InputContext;import sun.security.action.GetPropertyAction;import sun.awt.NullGraphics;import sun.awt.SunToolkit;/** * A <code>Window</code> object is a top-level window with no borders and no * menubar. * The default layout for a window is <code>BorderLayout</code>. * <p> * A window must have either a frame, dialog, or another window defined as its * owner when it's constructed. * <p> * In a multi-screen environment, you can create a <code>Window</code> * on a different screen device by constructing the <code>Window</code> * with {@link Window(Window, GraphicsConfiguration)}.  The * <code>GraphicsConfiguration</code> object is one of the * <code>GraphicsConfiguration</code> objects of the target screen device. * <p> * In a virtual device multi-screen environment in which the desktop * area could span multiple physical screen devices, the bounds of all * configurations are relative to the virtual device coordinate system. * The origin of the virtual-coordinate system is at the upper left-hand * corner of the primary physical screen.  Depending on the location of * the primary screen in the virtual device, negative coordinates are * possible, as shown in the following figure. * <p> * <img src="doc-files/MultiScreen.gif" * ALIGN=center HSPACE=10 VSPACE=7> * <p> * In such an environment, when calling <code>setLocation</code>, * you must pass a virtual coordinate to this method.  Similarly, * calling <code>getLocationOnScreen</code> on a <code>Window</code> returns * virtual device coordinates.  Call the <code>getBounds</code> method * of a <code>GraphicsConfiguration</code> to find its origin in the virtual * coordinate system. * <p> * The following code sets the location of a <code>Window</code> * at (10, 10) relative to the origin of the physical screen * of the corresponding <code>GraphicsConfiguration</code>.  If the * bounds of the <code>GraphicsConfiguration</code> is not taken * into account, the <code>Window</code> location would be set * at (10, 10) relative to the virtual-coordinate system and would appear * on the primary physical screen, which might be different from the * physical screen of the specified <code>GraphicsConfiguration</code>. * * <pre> *	Window w = new Window(Window owner, GraphicsConfiguration gc); *	Rectangle bounds = gc.getBounds(); *	w.setLocation(10 + bounds.x, 10 + bounds.y); * </pre> * * <!-- PBP/PP [4692065] --> * <!-- The following two paragraphs are borrowed from J2SE 1.5. --> * <a name="geometry"> * <em> * Note: the location and size of top-level windows (including * <code>Window</code>s, <code>Frame</code>s, and <code>Dialog</code>s) * are under the control of the <strike>desktop's</strike> window management system. * Calls to <code>setLocation</code>, <code>setSize</code>, and * <code>setBounds</code> are requests (not directives) which are * forwarded to the window management system.  <strike>Every effort will be * made to honor such requests.</strike>  <strike>However, i</strike>In some cases the window * management system may ignore such requests, or modify the requested * geometry in order to place and size the <code>Window</code> <strike>in a way * that more closely matches the desktop settings.</strike> * <em>appropriately</em>. * * Due to the asynchronous nature of native event handling, the results * returned by <code>getBounds</code>, <code>getLocation</code>, * <code>getLocationOnScreen</code>, and <code>getSize</code> might not  * reflect the actual geometry of the Window on screen until the last * request has been processed.  During the processing of subsequent * requests these values might change accordingly while the window * management system fulfills the requests. * </em> * <p> * <!-- The following language is specific to PBP, but might be picked up * in J2SE 1.6.--> * <em> * An application may set the size and location of an * invisible <code>Window</code> arbitrarily, * but the window management system may subsequently change * its size and/or location if and when the <code>Window</code> is * made visible.  One or more <code>ComponentEvent</code>s will * be generated to indicate the new geometry. * </em> * * <p> * Windows are capable of generating the following window events: * WindowOpened, WindowClosed. * * @version 	1.137, 02/09/01 * @author 	Sami Shaio * @author 	Arthur van Hoff * @see WindowEvent * @see #addWindowListener * @see java.awt.BorderLayout * @since       JDK1.0 */public class Window extends Container {    /**     * This represents the warning message that is     * to be displayed in a non secure window. ie :     * a window that has a security manager installed for     * which calling SecurityManager.checkTopLevelWindow()     * is false.  This message can be displayed anywhere in     * the window.     *     * @serial     * @see getWarningString()     */    String      warningString;    private int warningLabelHeight = 0;   //6221221    static final int OPENED = 0x01;    /**     * An Integer value representing the Window State.     *     * @serial     * @since 1.2     * @see show()     */    int state;    // ### Serialization problem.  FocusManager is package private    /**     * The Focus for the Window in question, and its components.     *     * @serial     * @since 1.2     * @See java.awt.FocusManager     */    //private FocusManager focusMgr;    /*     * JDK 1.1 serialVersionUID     */    private static final long serialVersionUID = 4497834738069338734L;    transient GraphicsConfiguration graphicsConfig;    transient WindowListener windowListener;    transient LightweightDispatcher dispatcher;    transient InputContext inputContext;    /**     * Constructs a new window in the default size.     *     * <p>First, if there is a security manager, its     * <code>checkTopLevelWindow</code>     * method is called with <code>this</code>     * as its argument     * to see if it's ok to display the window without a warning banner.     * If the default implementation of <code>checkTopLevelWindow</code>     * is used (that is, that method is not overriden), then this results in     * a call to the security manager's <code>checkPermission</code> method with an     * <code>AWTPermission("showWindowWithoutWarningBanner")</code>     * permission. It that method raises a SecurityException,     * <code>checkTopLevelWindow</code> returns false, otherwise it     * returns true. If it returns false, a warning banner is created.     *     * @see java.lang.SecurityManager#checkTopLevelWindow     */    Window(GraphicsConfiguration gc) {        setWarningString();   //6221221        if (gc == null)            gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();        GraphicsDevice device = gc.getDevice();        if (device.getType() != GraphicsDevice.TYPE_RASTER_SCREEN)            throw new IllegalArgumentException("Windows can only be created on screen devices");        if (device.getWindow() != null)            throw new UnsupportedOperationException("Cannot create more than one window per graphics device");        // The following bounds setting code is commented out and the functionality is moved        // to the Window.show() method in order to fix 6270960.        /*        Rectangle bounds = gc.getBounds();        x = bounds.x;        y = bounds.y;        width = bounds.width;        height = bounds.height;        */        graphicsConfig = gc;        foreground = Color.black;        background = Color.lightGray;        font = new Font(null, -1, 12);        visible = false;        dispatcher = new LightweightDispatcher(this);        setLayout(new BorderLayout());        device.setWindow(this);        //6221221        if (warningString != null) {            setWarningString(warningString);        }    }    // 6270960.    // Was: always ignore setBounds() request.    // Now: ignore whenever Window.isVisible() returns true.    public void setBounds(int x, int y, int width, int height) {        if (isVisible()) {            // Don't allow window to be moved or resized. The window always occupies            // the whole screen area.        } else {            super.setBounds(x, y, width, height);        }    }    void dispatchEventImpl(AWTEvent e) {        if (dispatcher.dispatchEvent(e)) {            // event was sent to a lightweight component.  The            // native-produced event sent to the native container            // must be properly disposed of by the peer, so it            // gets forwarded.  If the native host has been removed            // as a result of the sending the lightweight event,            // the peer reference will be null.            e.consume();            return;        }        switch (e.id) {        case ComponentEvent.COMPONENT_RESIZED:            invalidate();            validate();            repaint();            break;        }        super.dispatchEventImpl(e);    }    /*     * Dispatches an event to this component, without trying to forward     * it to any sub components     * @param e the event     */    void dispatchEventToSelf(AWTEvent e) {        super.dispatchEventImpl(e);    }    /**     * Disposes of the input methods and context, and removes the WeakReference     * which formerly pointed to this Window from the parent's owned Window     * list.     */    //protected void finalize() throws Throwable {}    /**     * Causes this Window to be sized to fit the preferred size     * and layouts of its subcomponents.  If the window and/or its owner     * are not yet displayable, both are made displayable before     * calculating the preferred size.  The Window will be validated     * after the preferredSize is calculated.     * @see Component#isDisplayable     */    public void pack() {        Container parent = this.parent;        if (parent != null && !parent.displayable) {            parent.addNotify();        }        if (!displayable) {            addNotify();        }        setSize(getPreferredSize());        validate();    }    /**     * Makes the Window visible. If the Window and/or its owner     * are not yet displayable, both are made displayable.  The     * Window will be validated prior to being made visible.     * If the Window is already visible, this will bring the Window     * to the front.     * @see       java.awt.Component#isDisplayable     * @see       java.awt.Window#toFront     * @see       java.awt.Component#setVisible     */    public void show() {        if (!displayable) {            addNotify();        }        // The following bounds setting code is moved from Window.ctor() method        // in order to fix 6270960.        // Basis toplevel always occupies the whole screen bounded by the        // graphics device.  We need to call setBounds() before validate()        // in order to calculate the right size for the containees.        Rectangle bounds = graphicsConfig.getBounds();        setBounds(bounds.x, bounds.y, bounds.width, bounds.height);        validate();        if (visible) {            toFront();        } else {            // 6229858 - need to call pShow because this is where we actually            // show the native widget            pShow();            super.show();            // If first time shown, generate WindowOpened event            if ((state & OPENED) == 0) {                Toolkit.getEventQueue().postEvent(new WindowEvent(this, WindowEvent.WINDOW_OPENED));                //SunToolkit.postEvent(appContext, new WindowEvent(this, WindowEvent.WINDOW_OPENED));                state |= OPENED;            }            // Using WINDOW_GAINED_FOCUS to bootstrap the process so that            // we could resue J2SE's implementation of             // DefaultKeyboardFocusManager.dispatchEvent(). Previously we            // we were posting WINDOW_ACTIVATED            SunToolkit.postEvent(appContext,new WindowEvent(this, WindowEvent.WINDOW_GAINED_FOCUS));            postPaintEvent();        }    }    // 6229858 - don't show the window until we actually show the frame    private native void pShow();    /**     * Releases all of the native screen resources used by this Window,     * its subcomponents, and all of its owned children. That is, the     * resources for these Components will be destroyed, any memory     * they consume will be returned to the OS, and they will be marked

⌨️ 快捷键说明

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