src/java.desktop/share/classes/java/awt/Frame.java

Print this page


   1 /*
   2  * Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.awt;
  26 


  27 import java.awt.peer.FramePeer;
  28 import java.awt.event.*;



  29 import java.util.ArrayList;
  30 import java.util.Arrays;
  31 import java.util.List;
  32 import java.util.Vector;
  33 import java.io.Serializable;
  34 import java.io.ObjectOutputStream;
  35 import java.io.ObjectInputStream;
  36 import java.io.IOException;
  37 import sun.awt.AppContext;
  38 import sun.awt.SunToolkit;
  39 import sun.awt.AWTAccessor;
  40 import java.lang.ref.WeakReference;
  41 import javax.accessibility.*;
  42 
  43 /**
  44  * A <code>Frame</code> is a top-level window with a title and a border.
  45  * <p>
  46  * The size of the frame includes any area designated for the
  47  * border.  The dimensions of the border area may be obtained
  48  * using the <code>getInsets</code> method, however, since
  49  * these dimensions are platform-dependent, a valid insets
  50  * value cannot be obtained until the frame is made displayable
  51  * by either calling <code>pack</code> or <code>show</code>.
  52  * Since the border area is included in the overall size of the
  53  * frame, the border effectively obscures a portion of the frame,
  54  * constraining the area available for rendering and/or displaying
  55  * subcomponents to the rectangle which has an upper-left corner
  56  * location of <code>(insets.left, insets.top)</code>, and has a size of
  57  * <code>width - (insets.left + insets.right)</code> by
  58  * <code>height - (insets.top + insets.bottom)</code>.
  59  * <p>
  60  * The default layout for a frame is <code>BorderLayout</code>.
  61  * <p>


 457      * name is null.
 458      */
 459     String constructComponentName() {
 460         synchronized (Frame.class) {
 461             return base + nameCounter++;
 462         }
 463     }
 464 
 465     /**
 466      * Makes this Frame displayable by connecting it to
 467      * a native screen resource.  Making a frame displayable will
 468      * cause any of its children to be made displayable.
 469      * This method is called internally by the toolkit and should
 470      * not be called directly by programs.
 471      * @see Component#isDisplayable
 472      * @see #removeNotify
 473      */
 474     public void addNotify() {
 475         synchronized (getTreeLock()) {
 476             if (peer == null) {
 477                 peer = getToolkit().createFrame(this);
 478             }
 479             FramePeer p = (FramePeer)peer;
 480             MenuBar menuBar = this.menuBar;
 481             if (menuBar != null) {
 482                 mbManagement = true;
 483                 menuBar.addNotify();
 484                 p.setMenuBar(menuBar);
 485             }
 486             p.setMaximizedBounds(maximizedBounds);
 487             super.addNotify();
 488         }
 489     }
 490 
 491     /**
 492      * Gets the title of the frame.  The title is displayed in the
 493      * frame's border.
 494      * @return    the title of this frame, or an empty string ("")
 495      *                if this frame doesn't have a title.
 496      * @see       #setTitle(String)
 497      */


   1 /*
   2  * Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.awt;
  26 
  27 import java.awt.event.KeyEvent;
  28 import java.awt.event.WindowEvent;
  29 import java.awt.peer.FramePeer;
  30 import java.io.IOException;
  31 import java.io.ObjectInputStream;
  32 import java.io.ObjectOutputStream;
  33 import java.io.Serializable;
  34 import java.util.ArrayList;


  35 import java.util.Vector;
  36 
  37 import javax.accessibility.AccessibleContext;
  38 import javax.accessibility.AccessibleRole;
  39 import javax.accessibility.AccessibleState;
  40 import javax.accessibility.AccessibleStateSet;
  41 
  42 import sun.awt.AWTAccessor;
  43 import sun.awt.SunToolkit;

  44 
  45 /**
  46  * A <code>Frame</code> is a top-level window with a title and a border.
  47  * <p>
  48  * The size of the frame includes any area designated for the
  49  * border.  The dimensions of the border area may be obtained
  50  * using the <code>getInsets</code> method, however, since
  51  * these dimensions are platform-dependent, a valid insets
  52  * value cannot be obtained until the frame is made displayable
  53  * by either calling <code>pack</code> or <code>show</code>.
  54  * Since the border area is included in the overall size of the
  55  * frame, the border effectively obscures a portion of the frame,
  56  * constraining the area available for rendering and/or displaying
  57  * subcomponents to the rectangle which has an upper-left corner
  58  * location of <code>(insets.left, insets.top)</code>, and has a size of
  59  * <code>width - (insets.left + insets.right)</code> by
  60  * <code>height - (insets.top + insets.bottom)</code>.
  61  * <p>
  62  * The default layout for a frame is <code>BorderLayout</code>.
  63  * <p>


 459      * name is null.
 460      */
 461     String constructComponentName() {
 462         synchronized (Frame.class) {
 463             return base + nameCounter++;
 464         }
 465     }
 466 
 467     /**
 468      * Makes this Frame displayable by connecting it to
 469      * a native screen resource.  Making a frame displayable will
 470      * cause any of its children to be made displayable.
 471      * This method is called internally by the toolkit and should
 472      * not be called directly by programs.
 473      * @see Component#isDisplayable
 474      * @see #removeNotify
 475      */
 476     public void addNotify() {
 477         synchronized (getTreeLock()) {
 478             if (peer == null) {
 479                 peer = getComponentFactory().createFrame(this);
 480             }
 481             FramePeer p = (FramePeer)peer;
 482             MenuBar menuBar = this.menuBar;
 483             if (menuBar != null) {
 484                 mbManagement = true;
 485                 menuBar.addNotify();
 486                 p.setMenuBar(menuBar);
 487             }
 488             p.setMaximizedBounds(maximizedBounds);
 489             super.addNotify();
 490         }
 491     }
 492 
 493     /**
 494      * Gets the title of the frame.  The title is displayed in the
 495      * frame's border.
 496      * @return    the title of this frame, or an empty string ("")
 497      *                if this frame doesn't have a title.
 498      * @see       #setTitle(String)
 499      */