frame.java

来自「This is a resource based on j2me embedde」· Java 代码 · 共 504 行 · 第 1/2 页

JAVA
504
字号
/* * @(#)Frame.java	1.23 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.io.ObjectOutputStream;import java.io.ObjectInputStream;import java.io.IOException;import java.lang.ref.WeakReference;/** * A Frame is a top-level window with a title and a border. * <p> * The size of the frame includes any area designated for the * border.  The dimensions of the border area can be obtained * using the <code>getInsets</code> method, however, since * these dimensions are platform-dependent, a valid insets * value cannot be obtained until the frame is made displayable * by either calling <code>pack</code> or <code>show</code>. * Since the border area is included in the overall size of the * frame, the border effectively obscures a portion of the frame, * constraining the area available for rendering and/or displaying * subcomponents to the rectangle which has an upper-left corner * location of <code>(insets.left, insets.top)</code>, and has a size of * <code>width - (insets.left + insets.right)</code> by * <code>height - (insets.top + insets.bottom)</code>. * <p> * The default layout for a frame is BorderLayout. * <p> * In a multi-screen environment, you can create a <code>Frame</code> * on a different screen device by constructing the <code>Frame</code> * with {@link Frame(GraphicsConfiguration)} or * {@link Frame(String title, 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-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>Frame</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 the <code>Frame</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>Frame</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> *      Frame f = new Frame(GraphicsConfiguration gc); *      Rectangle bounds = gc.getBounds(); *      f.setLocation(10 + bounds.x, 10 + bounds.y); * </pre> * * <p> * Frames are capable of generating the following types of window events: * WindowOpened, WindowClosing, WindowClosed, WindowIconified, * WindowDeiconified, WindowActivated, WindowDeactivated. * * <p> * <a name="restrictions"> * <h4>Restrictions</h4> * <em> * Implementations of Frame in Personal Basis Profile exhibit * certain restrictionsm, specifically: * <ul> * <li> Only a single instance of Frame is permited at a time. Attempts to * construct a second Frame will cause the constructor to throw * <code>java.lang.UnsupportedOperationException</code>.  See: * <ul> * <li> {@link #Frame()} * <li> {@link #Frame(GraphicsConfiguration)} * <li> {@link #Frame(String)} * <li> {@link #Frame(String, GraphicsConfiguration)} * </ul> * <li> An implementation may support only a single Frame size.  In such * a case, attempts to change the size of the Frame will fail silently. * See: * <ul> * <li> {@link #setSize(int, int)} * <li> {@link #setSize(Dimension)} * <li> {@link #setBounds(int, int, int, int)} * <li> {@link #setBounds(Rectangle)} * </ul> * <li> An implementation may support only a single Frame location.  In * such a case, attempts to change the location of the Frame will fail * silently.  See: * <ul> * <li> {@link #setLocation(int, int)} * <li> {@link #setLocation(Point)} * <li> {@link #setBounds(int, int, int, int)} * <li> {@link #setBounds(Rectangle)} * </ul> * <li> An implementation may prohibit iconification.  In * such a case, attempts to iconify the Frame will fail silently. * See: * <ul> * <li> {@link #setState} * </ul> * <li> An implementation need not support a visible title.  In such a * case, the methods {@link #setTitle} and {@link #getTitle} behave as * normal, but no title is visible to the user. * See: * <ul> * <li> {@link #setTitle} * </ul> * </ul> * </em> * * @version 	1.6 11/21/01 * @author 	Sami Shaio * @see WindowEvent * @see Window#addWindowListener * @since       JDK1.0 * */public class Frame extends Window {    public static final int     NORMAL = 0;    public static final int     ICONIFIED = 1;    /**     * This is the title of the frame.  It can be changed     * at any time.  <code>title</code> can be null and if     * this is the case the <code>title</code> = "".     *     * @serial     * @see getTitle()     * @see setTitle()     */    String 	title = "Untitled";    /**     * <code>icon</code> is the graphical way we can     * represent the frame.     * <code>icon</code> can be null, but obviously if     * you try to set the icon image <code>icon</code>     * cannot be null.     *     * @serial     * @see getIconImage()     * @see setIconImage()     */    Image  	icon;    // ### Serialization difference    // No field MenuBar menuBar    /**     * This field indicates whether the the frame is resizable     * This property can be changed at any time.     * <code>resizable</code> will be true if the frame is     * resizable, otherwise it will be false.     *     * @serial     * @see isResizable()     */    boolean	resizable = true; // 6248021    /**     * This field indicates whether the frame is undecorated.     * This property can only be changed while the frame is not displayable.     * <code>undecorated</code> will be true if the frame is     * undecorated, otherwise it will be false.     *     * @serial     * @see #setUndecorated(boolean)     * @see #isUndecorated()     * @see Component#isDisplayable()     * @since 1.4     */    boolean undecorated = false;    /**     * <code>mbManagement</code> is only used by the Motif implementation.     *     * @serial     */    //boolean	mbManagement = false;	/* used only by the Motif impl.	*/    private int state = NORMAL;    /*     * The Windows owned by the Frame.     * Note: in 1.2 this has been superceded by Window.ownedWindowList     *     * @serial     * @see java.awt.Window#ownedWindowList     */    //Vector ownedWindows;	    /*     * JDK 1.1 serialVersionUID     */    private static final long serialVersionUID = 2673458971256075116L;    /**     * Constructs a new instance of <code>Frame</code> that is     * initially invisible.  The title of the <code>Frame</code>     * is empty.     * <p>     * <em>Note: This operation is subject to     * <a href="#restrictions">restriction</a>     * in Personal Basis Profile.</em>     *     * @see Component#setSize     * @see Component#setVisible     */    public Frame() {        this("", (GraphicsConfiguration) null);    }    /**     * Create a <code>Frame</code> with the specified     * <code>GraphicsConfiguration</code> of     * a screen device.     *

⌨️ 快捷键说明

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