frame.java

来自「linux下建立JAVA虚拟机的源码KAFFE」· Java 代码 · 共 651 行 · 第 1/2 页

JAVA
651
字号
   *   * @param menuBar the new menu bar for this frame   */  public synchronized void setMenuBar(MenuBar menuBar)  {    if (this.menuBar != null)      remove(this.menuBar);    this.menuBar = menuBar;    if (menuBar != null)      {	MenuContainer parent = menuBar.getParent();	if (parent != null)	  parent.remove(menuBar);	menuBar.setParent(this);	if (peer != null)	  {	    if (menuBar != null)	      menuBar.addNotify();	    invalidateTree();	    ((FramePeer) peer).setMenuBar(menuBar);	  }      }  }  /**   * Tests whether or not this frame is resizable.  This will be    * <code>true</code> by default.   *   * @return <code>true</code> if this frame is resizable, <code>false</code>   *         otherwise   */  public boolean isResizable()  {    return resizable;  }  /**   * Sets the resizability of this frame to the specified value.   *   * @param resizable <code>true</code> to make the frame resizable,   * <code>false</code> to make it non-resizable   */  public synchronized void setResizable(boolean resizable)  {    this.resizable = resizable;    if (peer != null)      ((FramePeer) peer).setResizable(resizable);  }  /**   * Returns the cursor type of the cursor for this window.  This will   * be one of the constants in this class.   *   * @return the cursor type for this frame   *   * @deprecated Use <code>Component.getCursor()</code> instead.   */  public int getCursorType()  {    return getCursor().getType();  }  /**   * Sets the cursor for this window to the specified type.  The specified   * type should be one of the constants in this class.   *   * @param type the cursor type   *   * @deprecated Use <code>Component.setCursor(Cursor)</code> instead.   */  public void setCursor(int type)  {    setCursor(new Cursor(type));  }  /**   * Removes the specified menu component from this frame. If it is   * the current MenuBar it is removed from the frame. If it is a   * Popup it is removed from this component. If it is any other menu   * component it is ignored.   *   * @param menu the menu component to remove   */  public void remove(MenuComponent menu)  {    if (menu == menuBar)      {	if (menuBar != null)	  {	    if (peer != null)	      {		((FramePeer) peer).setMenuBar(null);		menuBar.removeNotify();	      }	    menuBar.setParent(null);	  }	menuBar = null;      }    else      super.remove(menu);  }  public void addNotify()  {    if (menuBar != null)      menuBar.addNotify();    if (peer == null)      peer = getToolkit ().createFrame (this);    super.addNotify();  }  public void removeNotify()  {    if (menuBar != null)      menuBar.removeNotify();    super.removeNotify();  }  /**   * Returns a debugging string describing this window.   *   * @return a debugging string describing this window   */  protected String paramString()  {    String title = getTitle();    String resizable = "";    if (isResizable ())      resizable = ",resizable";    String state = "";    switch (getState ())      {      case NORMAL:        state = ",normal";        break;      case ICONIFIED:        state = ",iconified";        break;      case MAXIMIZED_BOTH:        state = ",maximized-both";        break;      case MAXIMIZED_HORIZ:        state = ",maximized-horiz";        break;      case MAXIMIZED_VERT:        state = ",maximized-vert";        break;      }    return super.paramString () + ",title=" + title + resizable + state;  }  private static ArrayList weakFrames = new ArrayList();  private static void noteFrame(Frame f)  {    weakFrames.add(new WeakReference(f));  }  public static Frame[] getFrames()  {    int n = 0;    synchronized (weakFrames)    {      Iterator i = weakFrames.iterator();      while (i.hasNext())        {          WeakReference wr = (WeakReference) i.next();          if (wr.get() != null)            ++n;        }      if (n == 0)        return new Frame[0];      else        {          Frame[] frames = new Frame[n];          n = 0;          i = weakFrames.iterator();          while (i.hasNext())            {              WeakReference wr = (WeakReference) i.next();              if (wr.get() != null)                frames[n++] = (Frame) wr.get();            }          return frames;        }    }  }  public void setState(int state)  {    int current_state = getExtendedState ();    if (state == NORMAL        && (current_state & ICONIFIED) != 0)      setExtendedState(current_state | ICONIFIED);        if (state == ICONIFIED        && (current_state & ~ICONIFIED) == 0)      setExtendedState(current_state & ~ICONIFIED);  }  public int getState()  {    // FIXME: State might have changed in the peer... Must check.    return (state & ICONIFIED) != 0 ? ICONIFIED : NORMAL;  }  /**   * @since 1.4   */  public void setExtendedState(int state)  {    this.state = state;  }  /**   * @since 1.4   */  public int getExtendedState()  {    return state;  }  /**   * @since 1.4   */  public void setMaximizedBounds(Rectangle maximizedBounds)  {    this.maximizedBounds = maximizedBounds;  }  /**   * Returns the maximized bounds of this frame.   *   * @return the maximized rectangle, may be null   *   * @since 1.4   */  public Rectangle getMaximizedBounds()  {    return maximizedBounds;  }  /**   * Returns whether this frame is undecorated or not.   *    * @since 1.4   */  public boolean isUndecorated()  {    return undecorated;  }  /**   * Disables or enables decorations for this frame. This method can only be   * called while the frame is not displayable.   *    * @throws IllegalComponentStateException if this frame is displayable   *    * @since 1.4   */  public void setUndecorated(boolean undecorated)  {    if (isDisplayable())      throw new IllegalComponentStateException();    this.undecorated = undecorated;  }  /**   * Generate a unique name for this frame.   *   * @return a unique name for this frame   */  String generateName()  {    return "frame" + getUniqueLong();  }  private static synchronized long getUniqueLong()  {    return next_frame_number++;  }    protected class AccessibleAWTFrame extends AccessibleAWTWindow  {    private static final long serialVersionUID = -6172960752956030250L;    public AccessibleRole getAccessibleRole()    {      return AccessibleRole.FRAME;    }        public AccessibleStateSet getAccessibleState()    {      AccessibleStateSet states = super.getAccessibleStateSet();      if (isResizable())        states.add(AccessibleState.RESIZABLE);      if ((state & ICONIFIED) != 0)        states.add(AccessibleState.ICONIFIED);      return states;    }  }    /**   * Gets the AccessibleContext associated with this <code>Frame</code>.   * The context is created, if necessary.   *   * @return the associated context   */  public AccessibleContext getAccessibleContext()  {    // Create the context if this is the first request.    if (accessibleContext == null)      accessibleContext = new AccessibleAWTFrame();    return accessibleContext;  }}

⌨️ 快捷键说明

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