component.java

来自「Mac OS X 10.4.9 for x86 Source Code gcc」· Java 代码 · 共 2,357 行 · 第 1/5 页

JAVA
2,357
字号
   */  public void setBounds(Rectangle r)  {    setBounds (r.x, r.y, r.width, r.height);  }  /**   * Gets the x coordinate of the upper left corner. This is more efficient   * than getBounds().x or getLocation().x.   *   * @return the current x coordinate   * @since 1.2   */  public int getX()  {    return x;  }  /**   * Gets the y coordinate of the upper left corner. This is more efficient   * than getBounds().y or getLocation().y.   *   * @return the current y coordinate   * @since 1.2   */  public int getY()  {    return y;  }  /**   * Gets the width of the component. This is more efficient than   * getBounds().width or getSize().width.   *   * @return the current width   * @since 1.2   */  public int getWidth()  {    return width;  }  /**   * Gets the height of the component. This is more efficient than   * getBounds().height or getSize().height.   *   * @return the current width   * @since 1.2   */  public int getHeight()  {    return height;  }  /**   * Returns the bounds of this component. This allows reuse of an existing   * rectangle, if r is non-null.   *   * @param r the rectangle to use, or null   * @return the bounds   */  public Rectangle getBounds(Rectangle r)  {    if (r == null)      r = new Rectangle();    r.x = x;    r.y = y;    r.width = width;    r.height = height;    return r;  }  /**   * Returns the size of this component. This allows reuse of an existing   * dimension, if d is non-null.   *   * @param d the dimension to use, or null   * @return the size   */  public Dimension getSize(Dimension d)  {    if (d == null)      d = new Dimension();    d.width = width;    d.height = height;    return d;  }  /**   * Returns the location of this component. This allows reuse of an existing   * point, if p is non-null.   *   * @param p the point to use, or null   * @return the location   */  public Point getLocation(Point p)  {    if (p == null)      p = new Point();    p.x = x;    p.y = y;    return p;  }  /**   * Tests if this component is opaque. All "heavyweight" (natively-drawn)   * components are opaque. A component is opaque if it draws all pixels in   * the bounds; a lightweight component is partially transparent if it lets   * pixels underneath show through. Subclasses that guarantee that all pixels   * will be drawn should override this.   *   * @return true if this is opaque   * @see #isLightweight()   * @since 1.2   */  public boolean isOpaque()  {    return ! isLightweight();  }  /**   * Return whether the component is lightweight. That means the component has   * no native peer, but is displayable. This applies to subclasses of   * Component not in this package, such as javax.swing.   *   * @return true if the component has a lightweight peer   * @see #isDisplayable()   * @since 1.2   */  public boolean isLightweight()  {    return peer instanceof LightweightPeer;  }  /**   * Returns the component's preferred size.   *   * @return the component's preferred size   * @see #getMinimumSize()   * @see LayoutManager   */  public Dimension getPreferredSize()  {    return preferredSize();  }  /**   * Returns the component's preferred size.   *   * @return the component's preferred size   * @deprecated use {@link #getPreferredSize()} instead   */  public Dimension preferredSize()  {    if (prefSize == null)      if (peer == null)	return new Dimension(width, height);      else         prefSize = peer.getPreferredSize();    return prefSize;  }  /**   * Returns the component's minimum size.   *   * @return the component's minimum size   * @see #getPreferredSize()   * @see LayoutManager   */  public Dimension getMinimumSize()  {    return minimumSize();  }  /**   * Returns the component's minimum size.   *   * @return the component's minimum size   * @deprecated use {@link #getMinimumSize()} instead   */  public Dimension minimumSize()  {    if (minSize == null)      minSize = (peer != null ? peer.getMinimumSize()                 : new Dimension(width, height));    return minSize;  }  /**   * Returns the component's maximum size.   *   * @return the component's maximum size   * @see #getMinimumSize()   * @see #getPreferredSize()   * @see LayoutManager   */  public Dimension getMaximumSize()  {    return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);  }  /**   * Returns the preferred horizontal alignment of this component. The value   * returned will be between {@link #LEFT_ALIGNMENT} and   * {@link #RIGHT_ALIGNMENT}, inclusive.   *   * @return the preferred horizontal alignment of this component   */  public float getAlignmentX()  {    return CENTER_ALIGNMENT;  }  /**   * Returns the preferred vertical alignment of this component. The value   * returned will be between {@link #TOP_ALIGNMENT} and   * {@link #BOTTOM_ALIGNMENT}, inclusive.   *   * @return the preferred vertical alignment of this component   */  public float getAlignmentY()  {    return CENTER_ALIGNMENT;  }  /**   * Calls the layout manager to re-layout the component. This is called   * during validation of a container in most cases.   *   * @see #validate()   * @see LayoutManager   */  public void doLayout()  {    layout ();  }  /**   * Calls the layout manager to re-layout the component. This is called   * during validation of a container in most cases.   *   * @deprecated use {@link #doLayout()} instead   */  public void layout()  {    // Nothing to do unless we're a container.  }  /**   * Called to ensure that the layout for this component is valid. This is   * usually called on containers.   *   * @see #invalidate()   * @see #doLayout()   * @see LayoutManager   * @see Container#validate()   */  public void validate()  {    valid = true;  }  /**   * Invalidates this component and all of its parent components. This will   * cause them to have their layout redone. This is called frequently, so   * make it fast.   */  public void invalidate()  {    valid = false;    prefSize = null;    minSize = null;    if (parent != null && parent.valid)      parent.invalidate();  }  /**   * Returns a graphics object for this component. Returns <code>null</code>   * if this component is not currently displayed on the screen.   *   * @return a graphics object for this component   * @see #paint(Graphics)   */  public Graphics getGraphics()  {    if (peer != null)      {        Graphics gfx = peer.getGraphics();        if (gfx != null)          return gfx;        // create graphics for lightweight:        Container parent = getParent();        if (parent != null)          {            gfx = parent.getGraphics();            Rectangle bounds = getBounds();            gfx.setClip(bounds);            gfx.translate(bounds.x, bounds.y);            return gfx;          }      }    return null;  }  /**   * Returns the font metrics for the specified font in this component.   *   * @param font the font to retrieve metrics for   * @return the font metrics for the specified font   * @throws NullPointerException if font is null   * @see #getFont()   * @see Toolkit#getFontMetrics(Font)   */  public FontMetrics getFontMetrics(Font font)  {    return peer == null ? getToolkit().getFontMetrics(font)      : peer.getFontMetrics(font);  }  /**   * Sets the cursor for this component to the specified cursor. The cursor   * is displayed when the point is contained by the component, and the   * component is visible, displayable, and enabled. This is inherited by   * subcomponents unless they set their own cursor.   *   * @param cursor the new cursor for this component   * @see #isEnabled()   * @see #isShowing()   * @see #getCursor()   * @see #contains(int, int)   * @see Toolkit#createCustomCursor(Image, Point, String)   */  public void setCursor(Cursor cursor)  {    this.cursor = cursor;    if (peer != null)      peer.setCursor(cursor);  }  /**   * Returns the cursor for this component. If not set, this is inherited   * from the parent, or from Cursor.getDefaultCursor().   *   * @return the cursor for this component   */  public Cursor getCursor()  {    if (cursor != null)      return cursor;    return parent != null ? parent.getCursor() : Cursor.getDefaultCursor();  }  /**   * Tests if the cursor was explicitly set, or just inherited from the parent.   *   * @return true if the cursor has been set   * @since 1.4   */  public boolean isCursorSet()  {    return cursor != null;  }  /**   * Paints this component on the screen. The clipping region in the graphics   * context will indicate the region that requires painting. This is called   * whenever the component first shows, or needs to be repaired because   * something was temporarily drawn on top. It is not necessary for   * subclasses to call <code>super.paint(g)</code>. Components with no area   * are not painted.   *   * @param g the graphics context for this paint job   * @see #update(Graphics)   */  public void paint(Graphics g)  {    // Paint the heavyweight peer    if (!isLightweight() && peer != null)      peer.paint(g);  }  /**   * Updates this component. This is called in response to   * <code>repaint</code>. This method fills the component with the   * background color, then sets the foreground color of the specified   * graphics context to the foreground color of this component and calls   * the <code>paint()</code> method. The coordinates of the graphics are   * relative to this component. Subclasses should call either   * <code>super.update(g)</code> or <code>paint(g)</code>.   *   * @param g the graphics context for this update   *   * @see #paint(Graphics)   * @see #repaint()   */  public void update(Graphics g)  {    if (!isLightweight())      {        Rectangle clip = g.getClipBounds();        if (clip == null)          g.clearRect(0, 0, width, height);        else          g.clearRect(clip.x, clip.y, clip.width, clip.height);      }    paint(g);  }  /**   * Paints this entire component, including any sub-components.   *   * @param g the graphics context for this paint job   *    * @see #paint(Graphics)   */  public void paintAll(Graphics g)  {    if (! visible)      return;    paint(g);  }  /**   * Repaint this entire component. The <code>update()</code> method   * on this component will be called as soon as possible.   *   * @see #update(Graphics)   * @see #repaint(long, int, int, int, int)   */  public void repaint()  {    repaint(0, 0, 0, width, height);  }  /**   * Repaint this entire component. The <code>update()</code> method on this   * component will be called in approximate the specified number of   * milliseconds.   *   * @param tm milliseconds before this component should be repainted   * @see #paint(Graphics)   * @see #repaint(long, int, int, int, int)   */  public void repaint(long tm)  {    repaint(tm, 0, 0, width, height);  }  /**   * Repaints the specified rectangular region within this component. The   * <code>update</code> method on this component will be called as soon as   * possible. The coordinates are relative to this component.   *   * @param x the X coordinate of the upper left of the region to repaint   * @param y the Y coordinate of the upper left of the region to repaint   * @param w the width of the region to repaint   * @param h the height of the region to repaint   * @see #update(Graphics)   * @see #repaint(long, int, int, int, int)   */  public void repaint(int x, int y, int w, int h)  {    repaint(0, x, y, w, h);  }  /**   * Repaints the specified rectangular region within this component. The   * <code>update</code> method on this component will be called in   * approximately the specified number of milliseconds. The coordinates   * are relative to this component.   *

⌨️ 快捷键说明

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