home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / awt / swing / JFrame.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  27.0 KB  |  883 lines

  1. /*
  2.  * @(#)JFrame.java    1.41 98/02/12
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20. package java.awt.swing;
  21.  
  22. import java.awt.*;
  23. import java.awt.event.*;
  24. import java.beans.PropertyChangeListener;
  25. import java.util.Locale;
  26. import java.util.Vector;
  27. import java.io.Serializable;
  28.  
  29. import java.awt.accessibility.*;
  30.  
  31.  
  32. /**
  33.  * An extended version of java.awt.Frame that adds support for 
  34.  * interposing input and painting behavior in front of the frames
  35.  * children (see glassPane), support for special children that 
  36.  * are managed by a LayeredPane (see rootPane) and for Swing MenuBars.
  37.  * <p>
  38.  * The JFrame class is slightly incompatible with java.awt.Frame.
  39.  * JFrame contains a JRootPane as it's only child.
  40.  * The <b>contentPane</b> should be the parent of any children of the JFrame.
  41.  * This is different than java.awt.Frame, e.g. to add a child to 
  42.  * an AWT Frame you'd write:
  43.  * <pre>
  44.  *       frame.add(child);
  45.  * </pre>
  46.  * However using JFrame you need to add the child to the JFrames contentPane
  47.  * instead:
  48.  * <pre>
  49.  *       frame.getContentPane().add(child);
  50.  * </pre>
  51.  * The same is true for setting LayoutManagers, removing components,
  52.  * listing children, etc. All these methods should normally be sent to
  53.  * the contentPane() instead of the JFrame itself. The contentPane() will
  54.  * always be non-null. Attempting to set it to null will cause the JFrame
  55.  * to throw an exception. The default contentPane() will have a BorderLayout
  56.  * manager set on it. 
  57.  * <p>
  58.  * Please see the JRootPane documentation for a complete description of
  59.  * the contentPane, glassPane, and layeredPane properties.
  60.  * <p>
  61.  * Warning: serialized objects of this class will not be compatible with
  62.  * future swing releases.  The current serialization support is appropriate 
  63.  * for short term storage or RMI between Swing1.0 applications.  It will
  64.  * not be possible to load serialized Swing1.0 objects with future releases
  65.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  66.  * baseline for the serialized form of Swing objects.
  67.  *
  68.  * @see JRootPane
  69.  *
  70.  * @beaninfo
  71.  *      attribute: isContainer true
  72.  *      attribute: containerDelegate getContentPane
  73.  *    description: A toplevel window which can be minimized to an icon.
  74.  *
  75.  * @version 1.41 02/12/98
  76.  * @author Jeff Dinkins
  77.  * @author Georges Saab
  78.  * @author David Kloba
  79.  */
  80. public class JFrame extends Frame implements WindowConstants, Accessible, RootPaneContainer
  81. {
  82.     private int defaultCloseOperation = HIDE_ON_CLOSE;
  83.  
  84.     /**
  85.      * @see #getRootPane
  86.      * @see #setRootPane
  87.      */
  88.     protected JRootPane rootPane;
  89.  
  90.     /**
  91.      * @see #isRootPaneCheckingEnabled
  92.      * @see #setRootPaneCheckingEnabled
  93.      */
  94.     protected boolean rootPaneCheckingEnabled = false;
  95.  
  96.  
  97.     /**
  98.      * Constructs a new Frame that is initially invisible.
  99.      * @see Component#setSize
  100.      * @see Component#setVisible
  101.      */
  102.     public JFrame() {
  103.     super();    
  104.     frameInit();
  105.     }
  106.  
  107.     /**
  108.      * Constructs a new, initially invisible Frame with the specified
  109.      * title.
  110.      * @param title the title for the frame
  111.      * @see Component#setSize
  112.      * @see Component#setVisible
  113.      */
  114.     public JFrame(String title) {
  115.     super(title);
  116.     frameInit();
  117.     }
  118.  
  119.     /** Called by the constructors to init the JFrame properly. */
  120.     protected void frameInit() {
  121.         enableEvents(AWTEvent.KEY_EVENT_MASK | AWTEvent.WINDOW_EVENT_MASK);
  122.     setRootPane(createRootPane());
  123.         setBackground(UIManager.getColor("control"));
  124.     setRootPaneCheckingEnabled(true);
  125.     }
  126.  
  127.     /** Called by the constructor methods to create the default rootPane. */
  128.     protected JRootPane createRootPane() {
  129.     return new JRootPane();
  130.     }
  131.  
  132.     protected void processKeyEvent(KeyEvent e) {
  133.         super.processKeyEvent(e);
  134.         if(!e.isConsumed()) {
  135.             JComponent.processKeyBindingsForAllComponents(e,this,new Vector(),e.getID() == KeyEvent.KEY_PRESSED);
  136.         }
  137.     }
  138.  
  139.     protected void processWindowEvent(WindowEvent e) {
  140.         super.processWindowEvent(e);
  141.  
  142.         if (e.getID() == WindowEvent.WINDOW_CLOSING) {
  143.             switch(defaultCloseOperation) {
  144.               case HIDE_ON_CLOSE:
  145.                  setVisible(false);
  146.                  break;
  147.               case DISPOSE_ON_CLOSE:
  148.                  setVisible(false);
  149.                  dispose();
  150.                  break;
  151.               case DO_NOTHING_ON_CLOSE:
  152.                  default: 
  153.                  break;
  154.             }
  155.         }
  156.     }
  157.  
  158. //    public void setMenuBar(MenuBar menu) {  
  159. //        throw new IllegalComponentStateException("Please use setJMenuBar() with JFrame.");
  160. //    }
  161.  
  162.     /**
  163.      * Sets the operation which will happen by default when
  164.      * the user initiates a "close" on this frame.
  165.      * The possible choices are:
  166.      * <p>
  167.      * <ul>
  168.      * <li>DO_NOTHING_ON_CLOSE - do not do anything - require the
  169.      * program to handle the operation in the windowClosing
  170.      * method of a registered WindowListener object.
  171.      * <li>HIDE_ON_CLOSE - automatically hide the frame after
  172.      * invoking any registered WindowListener objects
  173.      * <li>DISPOSE_ON_CLOSE - automatically hide and dispose the 
  174.      * frame after invoking any registered WindowListener objects
  175.      * </ul>
  176.      * <p>
  177.      * The value is set to HIDE_ON_CLOSE by default.
  178.      * @see #addWindowListener
  179.      * @see #getDefaultCloseOperation
  180.      *
  181.      * @beaninfo
  182.      *   preferred: true
  183.      *        enum: DO_NOTHING_ON_CLOSE WindowConstants.DO_NOTHING_ON_CLOSE
  184.      *              HIDE_ON_CLOSE       WindowConstants.HIDE_ON_CLOSE
  185.      *              DISPOSE_ON_CLOSE    WindowConstants.DISPOSE_ON_CLOSE
  186.      * description: The frame's default close operation.
  187.      */
  188.     public void setDefaultCloseOperation(int operation) {
  189.         this.defaultCloseOperation = operation;
  190.     }
  191.  
  192.  
  193.    /**
  194.     * Returns the operation which occurs when the user
  195.     * initiates a "close" on this frame.
  196.     *
  197.     * @return an int indicating the window-close operation
  198.     * @see #setDefaultCloseOperation
  199.     */
  200.     public int getDefaultCloseOperation() {
  201.         return defaultCloseOperation;
  202.     }
  203.  
  204.  
  205.     /** 
  206.      * Just calls <code>paint(g)</code>.  This method was overridden to 
  207.      * prevent an unneccessary call to clear the background.
  208.      */
  209.     public void update(Graphics g) {
  210.         paint(g);
  211.     }
  212.  
  213.    /**
  214.     * Sets the menubar for this frame.
  215.     * @param menubar the menubar being placed in the frame
  216.     *
  217.     * @see #getJMenuBar
  218.     *
  219.     * @beaninfo
  220.     *      hidden: true
  221.     * description: The menubar for accessing pulldown menus from this frame.
  222.     */
  223.     public void setJMenuBar(JMenuBar menubar) {
  224.     getRootPane().setMenuBar(menubar);
  225.     }
  226.  
  227.    /**
  228.     * Returns the menubar set on this frame.
  229.     *
  230.     * @see #setJMenuBar
  231.     */
  232.     public JMenuBar getJMenuBar() { 
  233.     return getRootPane().getMenuBar(); 
  234.     }
  235.  
  236.     /**
  237.      * @return true if add and setLayout should be checked
  238.      * @see #addImpl
  239.      * @see #setLayout
  240.      * @see #setRootPaneCheckingEnabled
  241.      */
  242.     protected boolean isRootPaneCheckingEnabled() {
  243.     return rootPaneCheckingEnabled;
  244.     }
  245.  
  246.  
  247.     /**
  248.      * If true then calls to add() and setLayout() will cause an exception
  249.      * to be thrown.  
  250.      *
  251.      * @see #addImpl
  252.      * @see #setLayout
  253.      * @see #isRootPaneCheckingEnabled
  254.      * @beaninfo
  255.      *      hidden: true
  256.      * description: Whether the add and setLayout methods throw exceptions when invoked.
  257.      */
  258.     protected void setRootPaneCheckingEnabled(boolean enabled) {
  259.     rootPaneCheckingEnabled = enabled;
  260.     }
  261.  
  262.  
  263.     /**
  264.      * Create an runtime exception with a message like:
  265.      * <pre>
  266.      * "Do not use JFrame.add() use JFrame.getContentPane().add() instead"
  267.      * </pre>
  268.      */
  269.     private Error createRootPaneException(String op) {
  270.     String type = getClass().getName();
  271.     return new Error(
  272.             "Do not use " + type + "." + op + "() use " 
  273.                           + type + ".getContentPane()." + op + "() instead");
  274.     }
  275.  
  276.  
  277.     /**
  278.      * By default, children may not be added directly to a this component,
  279.      * they must be added to its contentPane instead.  For example:
  280.      * <pre>
  281.      * thisComponent.getContentPane().add(child)
  282.      * </pre>
  283.      * An attempt to add to directly to this component will cause an
  284.      * runtime exception to be thrown.  Subclasses can disable this
  285.      * behavior.
  286.      * 
  287.      * @see #setRootPaneCheckingEnabled
  288.      * @exception Error if called with rootPaneChecking true
  289.      */
  290.     protected void addImpl(Component comp, Object constraints, int index) 
  291.     {
  292.         if(isRootPaneCheckingEnabled()) {
  293.         throw createRootPaneException("add");
  294.     }
  295.     else {
  296.         super.addImpl(comp, constraints, index);
  297.     }
  298.     }
  299.  
  300.  
  301.     /**
  302.      * By default the layout of this component may not be set,
  303.      * the layout of its contentPane should be set instead.  
  304.      * For example:
  305.      * <pre>
  306.      * thiComponent.getContentPane().setLayout(new BorderLayout())
  307.      * </pre>
  308.      * An attempt to set the layout of this component will cause an
  309.      * runtime exception to be thrown.  Subclasses can disable this
  310.      * behavior.
  311.      * 
  312.      * @see #setRootPaneCheckingEnabled
  313.      * @exception Error if called with rootPaneChecking true
  314.      */
  315.     public void setLayout(LayoutManager manager) {
  316.         if(isRootPaneCheckingEnabled()) {
  317.         throw createRootPaneException("setLayout");
  318.     }
  319.     else {
  320.         super.setLayout(manager);
  321.     }
  322.     }
  323.  
  324.  
  325.     /**
  326.      * Returns the rootPane object for this frame.
  327.      *
  328.      * @see #setRootPane
  329.      * @see RootPaneContainer#getRootPane
  330.      */
  331.     public JRootPane getRootPane() { 
  332.     return rootPane; 
  333.     }
  334.  
  335.  
  336.     /**
  337.      * Sets the rootPane property.  This method is called by the constructor.
  338.      * @param root the rootPane object for this frame
  339.      *
  340.      * @see #getRootPane
  341.      * @see RootPaneContainer#setRootPane
  342.      *
  343.      * @beaninfo
  344.      *   hidden: true
  345.      * description: the RootPane object for this frame.
  346.      */
  347.     protected void setRootPane(JRootPane root) 
  348.     {
  349.     if(rootPane != null) {
  350.         remove(rootPane);
  351.     }
  352.     rootPane = root;
  353.     if(rootPane != null) {
  354.         boolean checkingEnabled = isRootPaneCheckingEnabled();
  355.         try {
  356.         setRootPaneCheckingEnabled(false);
  357.         add(rootPane, BorderLayout.CENTER);
  358.         }
  359.         finally {
  360.         setRootPaneCheckingEnabled(checkingEnabled);
  361.         }
  362.         }
  363.     }
  364.  
  365.  
  366.     /**
  367.      * Returns the contentPane object for this frame.
  368.      *
  369.      * @see #setContentPane
  370.      * @see RootPaneContainer#getContentPane
  371.      */
  372.     public Container getContentPane() { 
  373.     return getRootPane().getContentPane(); 
  374.     }
  375.  
  376.     /**
  377.      * Sets the contentPane property.  This method is called by the constructor.
  378.      * @param contentPane the contentPane object for this frame
  379.      *
  380.      * @see #getContentPane
  381.      * @see RootPaneContainer#setContentPane
  382.      *
  383.      * @beaninfo
  384.      *     hidden: true
  385.      *     description: The client area of the frame where child 
  386.      *                  components are normally inserted.
  387.      */
  388.     public void setContentPane(Container contentPane) {
  389.     getRootPane().setContentPane(contentPane);
  390.     }
  391.  
  392.     /**
  393.      * Returns the layeredPane object for this frame.
  394.      *
  395.      * @see #setLayeredPane
  396.      * @see RootPaneContainer#getLayeredPane
  397.      */
  398.     public JLayeredPane getLayeredPane() { 
  399.     return getRootPane().getLayeredPane(); 
  400.     }
  401.  
  402.     /**
  403.      * Sets the layeredPane property.  This method is called by the constructor.
  404.      * @param layeredPane the layeredPane object for this frame
  405.      *
  406.      * @see #getLayeredPane
  407.      * @see RootPaneContainer#setLayeredPane
  408.      *
  409.      * @beaninfo
  410.      *     hidden: true
  411.      *     description: The pane which holds the various frame layers.
  412.      */
  413.     public void setLayeredPane(JLayeredPane layeredPane) {
  414.     getRootPane().setLayeredPane(layeredPane);
  415.     }
  416.  
  417.     /**
  418.      * Returns the glassPane object for this frame.
  419.      *
  420.      * @see #setGlassPane
  421.      * @see RootPaneContainer#getGlassPane
  422.      */
  423.     public Component getGlassPane() { 
  424.     return getRootPane().getGlassPane(); 
  425.     }
  426.  
  427.     /**
  428.      * Sets the glassPane property. 
  429.      * This method is called by the constructor.
  430.      * @param glassPane the glassPane object for this frame
  431.      *
  432.      * @see #getGlassPane
  433.      * @see RootPaneContainer#setGlassPane
  434.      *
  435.      * @beaninfo
  436.      *     hidden: true
  437.      *     description: A transparent pane used for menu rendering.
  438.      */
  439.     public void setGlassPane(Component glassPane) {
  440.     getRootPane().setGlassPane(glassPane);
  441.     }
  442.  
  443.  
  444.  
  445. /////////////////
  446. // Accessibility support
  447. ////////////////
  448.  
  449.     protected AccessibleContext accessibleContext = null;
  450.  
  451.     /**
  452.      * Get the AccessibleContext associated with this JFrame
  453.      *
  454.      * @return the AccessibleContext of this JFrame
  455.      */
  456.     public AccessibleContext getAccessibleContext() {
  457.     if (accessibleContext == null) {
  458.         accessibleContext = new AccessibleJFrame();
  459.     }
  460.     return accessibleContext;
  461.     }
  462.  
  463.     protected class AccessibleJFrame extends AccessibleContext
  464.     implements Serializable, AccessibleComponent {
  465.  
  466.         // AccessibleContext methods
  467.         /**
  468.          * Get the accessible name of this object.  
  469.          *
  470.          * @return the localized name of the object -- can be null if this 
  471.          * object does not have a name
  472.          */
  473.         public String getAccessibleName() {
  474.             if (accessibleName != null) {
  475.                 return accessibleName;
  476.             } else {
  477.                 if (getTitle() == null) {
  478.                 return super.getAccessibleName();
  479.                 } else {
  480.                 return getTitle();
  481.                 }
  482.             }
  483.         }
  484.  
  485.         /**
  486.          * Get the role of this object.
  487.          *
  488.          * @return an instance of AccessibleRole describing the role of the 
  489.      * object
  490.          * @see AccessibleRole
  491.          */
  492.         public AccessibleRole getAccessibleRole() {
  493.         return AccessibleRole.FRAME;
  494.         }
  495.  
  496.         /**
  497.          * Get the state of this object.
  498.          *
  499.          * @return an instance of AccessibleStateSet containing the current 
  500.      * state set of the object
  501.          * @see AccessibleState
  502.          */
  503.         public AccessibleStateSet getAccessibleStateSet() {
  504.         AccessibleStateSet states = SwingUtilities.getAccessibleStateSet(JFrame.this);
  505.         if (isResizable()) {
  506.         states.add(AccessibleState.RESIZABLE);
  507.         }
  508.         if (getFocusOwner() != null) {
  509.         states.add(AccessibleState.ACTIVE);
  510.         }    
  511.         // FIXME:  [[[WDW - should also return ICONIFIED and ICONIFIABLE
  512.         // if we can ever figure these out]]]
  513.         return states;
  514.         }
  515.  
  516.         /**
  517.          * Get the Accessible parent of this object.  If the parent of this
  518.          * object implements Accessible, this method should simply return
  519.          * getParent().
  520.          *
  521.          * @return the Accessible parent of this object -- can be null if this
  522.          * object does not have an Accessible parent
  523.          */
  524.         public Accessible getAccessibleParent() {
  525.             Container parent = getParent();
  526.             if (parent instanceof Accessible) {
  527.                 return (Accessible) parent;
  528.             } else {
  529.                 return null;
  530.             }
  531.         }
  532.  
  533.         /**
  534.          * Get the index of this object in its accessible parent. 
  535.          *
  536.          * @return the index of this object in its parent; -1 if this 
  537.          * object does not have an accessible parent.
  538.          * @see #getAccessibleParent
  539.          */
  540.         public int getAccessibleIndexInParent() {
  541.         return SwingUtilities.getAccessibleIndexInParent(JFrame.this);
  542.         }
  543.  
  544.         /**
  545.          * Returns the number of accessible children in the object.  If all
  546.          * of the children of this object implement Accessible, than this
  547.          * method should return the number of children of this object.
  548.          *
  549.          * @return the number of accessible children in the object.
  550.          */
  551.         public int getAccessibleChildrenCount() {
  552.         return SwingUtilities.getAccessibleChildrenCount(JFrame.this);
  553.         }
  554.  
  555.         /**
  556.          * Return the nth Accessible child of the object.  
  557.          *
  558.          * @param i zero-based index of child
  559.          * @return the nth Accessible child of the object
  560.          */
  561.         public Accessible getAccessibleChild(int i) {
  562.             return SwingUtilities.getAccessibleChild(JFrame.this,i);
  563.         }
  564.  
  565.         /**
  566.          * Return the locale of this object.
  567.      *
  568.          * @return the locale of this object
  569.          */
  570.         public Locale getLocale() {
  571.             return JFrame.this.getLocale();
  572.         }
  573.  
  574.         /**
  575.          * Get the AccessibleComponent associated with this object if one
  576.          * exists.  Otherwise return null.
  577.          */
  578.     public AccessibleComponent getAccessibleComponent() {
  579.         return this;
  580.     }
  581.  
  582.  
  583.         // AccessibleComponent methods
  584.         //
  585.         /**
  586.          * Get the background color of this object.
  587.          *
  588.          * @return the background color, if supported, of the object; 
  589.          * otherwise, null
  590.          */
  591.         public Color getBackground() {
  592.         return JFrame.this.getBackground();
  593.     }
  594.  
  595.         /**
  596.          * Set the background color of this object.
  597.          *
  598.          * @param c the new Color for the background
  599.          */
  600.         public void setBackground(Color c) {
  601.         JFrame.this.setBackground(c);
  602.     }
  603.  
  604.         /**
  605.          * Get the foreground color of this object.
  606.          *
  607.          * @return the foreground color, if supported, of the object; 
  608.          * otherwise, null
  609.          */
  610.         public Color getForeground() {
  611.         return JFrame.this.getForeground();
  612.     }
  613.  
  614.         /**
  615.          * Set the foreground color of this object.
  616.          *
  617.          * @param c the new Color for the foreground
  618.          */
  619.         public void setForeground(Color c) {
  620.         JFrame.this.setForeground(c);
  621.     }
  622.  
  623.         /**
  624.          * Get the Cursor of this object.
  625.          *
  626.          * @return the Cursor, if supported, of the object; otherwise, null
  627.          */
  628.         public Cursor getCursor() {
  629.         return JFrame.this.getCursor();
  630.     }
  631.  
  632.         /**
  633.          * Set the Cursor of this object.
  634.          *
  635.          * @param c the new Cursor for the object
  636.          */
  637.         public void setCursor(Cursor cursor) {
  638.         JFrame.this.setCursor(cursor);
  639.     }
  640.  
  641.         /**
  642.          * Get the Font of this object.
  643.          *
  644.          * @return the Font,if supported, for the object; otherwise, null
  645.          */
  646.         public Font getFont() {
  647.         return JFrame.this.getFont();
  648.     }
  649.  
  650.         /**
  651.          * Set the Font of this object.
  652.          *
  653.          * @param f the new Font for the object
  654.          */
  655.         public void setFont(Font f) {
  656.         JFrame.this.setFont(f);
  657.     }
  658.  
  659.         /**
  660.          * Get the FontMetrics of this object.
  661.          *
  662.          * @param f the Font
  663.          * @return the FontMetrics, if supported, the object; otherwise, null
  664.          * @see getFont
  665.          */
  666.         public FontMetrics getFontMetrics(Font f) {
  667.         return JFrame.this.getFontMetrics(f);
  668.     }
  669.  
  670.         /**
  671.          * Determine if the object is enabled.
  672.          *
  673.          * @return true if object is enabled; otherwise, false
  674.          */
  675.         public boolean isEnabled() {
  676.         return JFrame.this.isEnabled();
  677.     }
  678.  
  679.         /**
  680.          * Set the enabled state of the object.
  681.          *
  682.          * @param b if true, enables this object; otherwise, disables it 
  683.          */
  684.         public void setEnabled(boolean b) {
  685.         JFrame.this.setEnabled(b);
  686.     }
  687.     
  688.         /**
  689.          * Determine if the object is visible.  Note: this means that the
  690.          * object intends to be visible; however, it may not in fact be
  691.          * showing on the screen because one of the objects that this object
  692.          * is contained by is not visible.  To determine if an object is
  693.          * showing on the screen, use isShowing().
  694.          *
  695.          * @return true if object is visible; otherwise, false
  696.          */
  697.         public boolean isVisible() {
  698.         return JFrame.this.isVisible();
  699.     }
  700.  
  701.         /**
  702.          * Set the visible state of the object.
  703.          *
  704.          * @param b if true, shows this object; otherwise, hides it 
  705.          */
  706.         public void setVisible(boolean b) {
  707.         JFrame.this.setVisible(b);
  708.     }
  709.  
  710.         /**
  711.          * Determine if the object is showing.  This is determined by checking
  712.          * the visibility of the object and ancestors of the object.  Note: 
  713.      * this will return true even if the object is obscured by another 
  714.      * (for example, it happens to be underneath a menu that was pulled 
  715.      * down).
  716.          *
  717.          * @return true if object is showing; otherwise, false
  718.          */
  719.         public boolean isShowing() {
  720.         return JFrame.this.isShowing();
  721.     }
  722.  
  723.         /** 
  724.          * Checks whether the specified point is within this object's bounds,
  725.          * where the point's x and y coordinates are defined to be relative to 
  726.      * the coordinate system of the object. 
  727.          *
  728.          * @param p the Point relative to the coordinate system of the object
  729.          * @return true if object contains Point; otherwise false
  730.          */
  731.         public boolean contains(Point p) {
  732.         return JFrame.this.contains(p);
  733.     }
  734.     
  735.         /** 
  736.          * Returns the location of the object on the screen.
  737.          *
  738.          * @return location of object on screen -- can be null if this object
  739.          * is not on the screen
  740.          */
  741.         public Point getLocationOnScreen() {
  742.         return JFrame.this.getLocationOnScreen();
  743.     }
  744.  
  745.         /** 
  746.          * Gets the location of the object relative to the parent in the form 
  747.          * of a point specifying the object's top-left corner in the screen's 
  748.          * coordinate space.
  749.          *
  750.          * @return An instance of Point representing the top-left corner of 
  751.      * the objects's bounds in the coordinate space of the screen; null if
  752.          * this object or its parent are not on the screen
  753.          */
  754.     public Point getLocation() {
  755.         return JFrame.this.getLocation();
  756.     }
  757.  
  758.         /** 
  759.          * Sets the location of the object relative to the parent.
  760.          */
  761.         public void setLocation(Point p) {
  762.         JFrame.this.setLocation(p);
  763.     }
  764.  
  765.         /** 
  766.          * Gets the bounds of this object in the form of a Rectangle object. 
  767.          * The bounds specify this object's width, height, and location
  768.          * relative to its parent. 
  769.          *
  770.          * @return A rectangle indicating this component's bounds; null if 
  771.      * this object is not on the screen.
  772.          */
  773.         public Rectangle getBounds() {
  774.         return JFrame.this.getBounds();
  775.     }
  776.  
  777.         /** 
  778.          * Sets the bounds of this object in the form of a Rectangle object. 
  779.          * The bounds specify this object's width, height, and location
  780.          * relative to its parent.
  781.          *    
  782.          * @param A rectangle indicating this component's bounds
  783.          */
  784.         public void setBounds(Rectangle r) {
  785.         JFrame.this.setBounds(r);
  786.     }
  787.  
  788.         /** 
  789.          * Returns the size of this object in the form of a Dimension object. 
  790.          * The height field of the Dimension object contains this objects's
  791.          * height, and the width field of the Dimension object contains this 
  792.      * object's width. 
  793.          *
  794.          * @return A Dimension object that indicates the size of this 
  795.      * component; null if this object is not on the screen
  796.          */
  797.         public Dimension getSize() {
  798.         return JFrame.this.getSize();
  799.     }
  800.  
  801.         /** 
  802.          * Resizes this object so that it has width width and height. 
  803.          *    
  804.          * @param d - The dimension specifying the new size of the object. 
  805.          */
  806.         public void setSize(Dimension d) {
  807.         JFrame.this.setSize(d);
  808.     }
  809.  
  810.         /**
  811.          * Returns the Accessible child, if one exists, contained at the local
  812.      * coordinate Point.
  813.          *
  814.          * @param p The point defining the top-left corner of the Accessible, 
  815.      * given in the coordinate space of the object's parent. 
  816.          * @return the Accessible, if it exists, at the specified location; 
  817.      * else null
  818.          */
  819.         public Accessible getAccessibleAt(Point p) {
  820.             Accessible a;
  821.             AccessibleContext ac;
  822.             AccessibleComponent acmp;
  823.             Point location;
  824.             int nchildren = getAccessibleChildrenCount();
  825.             for (int i=0; i < nchildren; i++) {
  826.                 a = getAccessibleChild(i);
  827.                 if ((a != null)) {
  828.                     ac = a.getAccessibleContext();
  829.                     if (ac != null) {
  830.                         acmp = ac.getAccessibleComponent();
  831.                         if ((acmp != null) && (acmp.isShowing())) {
  832.                             location = acmp.getLocation();
  833.                             Point np = new Point(p.x-location.x, p.y-location.y)
  834. ;
  835.                             if (acmp.contains(np)){
  836.                                 return a;
  837.                             }
  838.                         }
  839.                     }
  840.                 }
  841.             }
  842.             return (Accessible) JFrame.this;
  843. //        return SwingUtilities.getAccessibleAt(JFrame.this,p);
  844.     }
  845.  
  846.         /**
  847.          * Returns whether this object can accept focus or not.
  848.          *
  849.          * @return true if object can accept focus; otherwise false
  850.          */
  851.         public boolean isFocusTraversable() {
  852.         return JFrame.this.isFocusTraversable();
  853.     }
  854.  
  855.         /**
  856.          * Requests focus for this object.
  857.          */
  858.         public void requestFocus() {
  859.         JFrame.this.requestFocus();
  860.         }
  861.  
  862.         /**
  863.          * Adds the specified focus listener to receive focus events from this 
  864.          * component. 
  865.          *
  866.          * @param l the focus listener
  867.          */
  868.         public void addFocusListener(FocusListener l) {
  869.         JFrame.this.addFocusListener(l);
  870.     }
  871.  
  872.         /**
  873.          * Removes the specified focus listener so it no longer receives focus 
  874.          * events from this component.
  875.          *
  876.          * @param l the focus listener
  877.          */
  878.         public void removeFocusListener(FocusListener l) {
  879.         JFrame.this.removeFocusListener(l);
  880.     }
  881.     } // inner class AccessibleJFrame
  882. }
  883.