📄 graphics.java
字号:
* clipping area and the specified rectangle.
* This method can only be used to make the current clip smaller.
* To set the current clip larger, use any of the setClip methods.
* Rendering operations have no effect outside of the clipping area.
* @param x the x coordinate of the rectangle to intersect the clip with
* @param y the y coordinate of the rectangle to intersect the clip with
* @param width the width of the rectangle to intersect the clip with
* @param height the height of the rectangle to intersect the clip with
* @see #setClip(int, int, int, int)
* @see #setClip(Shape)
*/
public abstract void clipRect(int x, int y, int width, int height);
/**
* Sets the current clip to the rectangle specified by the given
* coordinates.
* Rendering operations have no effect outside of the clipping area.
* @param x the <i>x</i> coordinate of the new clip rectangle.
* @param y the <i>y</i> coordinate of the new clip rectangle.
* @param width the width of the new clip rectangle.
* @param height the height of the new clip rectangle.
* @see java.awt.Graphics#clipRect
* @see java.awt.Graphics#setClip(Shape)
* @since JDK1.1
*/
public abstract void setClip(int x, int y, int width, int height);
/**
* Gets the current clipping area.
* @return a <code>Shape</code> object representing the
* current clipping area.
* @see java.awt.Graphics#getClipBounds
* @see java.awt.Graphics#clipRect
* @see java.awt.Graphics#setClip(int, int, int, int)
* @see java.awt.Graphics#setClip(Shape)
* @since JDK1.1
*/
public abstract Shape getClip();
/**
* Sets the current clipping area to an arbitrary clip shape.
* Not all objects which implement the <code>Shape</code>
* interface can be used to set the clip. The only
* <code>Shape</code> objects which are guaranteed to be
* supported are <code>Shape</code> objects which are
* obtained via the <code>getClip</code> method and via
* <code>Rectangle</code> objects.
* @see java.awt.Graphics#getClip()
* @see java.awt.Graphics#clipRect
* @see java.awt.Graphics#setClip(int, int, int, int)
* @since JDK1.1
*/
public abstract void setClip(Shape clip);
/**
* Copies an area of the component by a distance specified by
* <code>dx</code> and <code>dy</code>. From the point specified
* by <code>x</code> and <code>y</code>, this method
* copies downwards and to the right. To copy an area of the
* component to the left or upwards, specify a negative value for
* <code>dx</code> or <code>dy</code>.
* If a portion of the source rectangle lies outside the bounds
* of the component, or is obscured by another window or component,
* <code>copyArea</code> will be unable to copy the associated
* pixels. The area that is omitted can be refreshed by calling
* the component's <code>paint</code> method.
* @param x the <i>x</i> coordinate of the source rectangle.
* @param y the <i>y</i> coordinate of the source rectangle.
* @param width the width of the source rectangle.
* @param height the height of the source rectangle.
* @param dx the horizontal distance to copy the pixels.
* @param dy the vertical distance to copy the pixels.
* @since JDK1.0
*/
public abstract void copyArea(int x, int y, int width, int height,
int dx, int dy);
/**
* Draws a line, using the current color, between the points
* <code>(x1, y1)</code> and <code>(x2, y2)</code>
* in this graphics context's coordinate system.
* @param x1 the first point's <i>x</i> coordinate.
* @param y1 the first point's <i>y</i> coordinate.
* @param x2 the second point's <i>x</i> coordinate.
* @param y2 the second point's <i>y</i> coordinate.
* @since JDK1.0
*/
public abstract void drawLine(int x1, int y1, int x2, int y2);
/**
* Fills the specified rectangle.
* The left and right edges of the rectangle are at
* <code>x</code> and <code>x + width - 1</code>.
* The top and bottom edges are at
* <code>y</code> and <code>y + height - 1</code>.
* The resulting rectangle covers an area
* <code>width</code> pixels wide by
* <code>height</code> pixels tall.
* The rectangle is filled using the graphics context's current color.
* @param x the <i>x</i> coordinate
* of the rectangle to be filled.
* @param y the <i>y</i> coordinate
* of the rectangle to be filled.
* @param width the width of the rectangle to be filled.
* @param height the height of the rectangle to be filled.
* @see java.awt.Graphics#fillRect
* @see java.awt.Graphics#clearRect
* @since JDK1.0
*/
public abstract void fillRect(int x, int y, int width, int height);
/**
* Draws the outline of the specified rectangle.
* The left and right edges of the rectangle are at
* <code>x</code> and <code>x + width</code>.
* The top and bottom edges are at
* <code>y</code> and <code>y + height</code>.
* The rectangle is drawn using the graphics context's current color.
* @param x the <i>x</i> coordinate
* of the rectangle to be drawn.
* @param y the <i>y</i> coordinate
* of the rectangle to be drawn.
* @param width the width of the rectangle to be drawn.
* @param height the height of the rectangle to be drawn.
* @see java.awt.Graphics#fillRect
* @see java.awt.Graphics#clearRect
* @since JDK1.0
*/
public void drawRect(int x, int y, int width, int height) {
if ((width < 0) || (height < 0)) {
return;
}
if (height == 0 || width == 0) {
drawLine(x, y, x + width, y + height);
} else {
drawLine(x, y, x + width - 1, y);
drawLine(x + width, y, x + width, y + height - 1);
drawLine(x + width, y + height, x + 1, y + height);
drawLine(x, y + height, x, y + 1);
}
}
/**
* Clears the specified rectangle by filling it with the background
* color of the current drawing surface. This operation does not
* use the current paint mode.
* <p>
* Beginning with Java 1.1, the background color
* of offscreen images may be system dependent. Applications should
* use <code>setColor</code> followed by <code>fillRect</code> to
* ensure that an offscreen image is cleared to a specific color.
* @param x the <i>x</i> coordinate of the rectangle to clear.
* @param y the <i>y</i> coordinate of the rectangle to clear.
* @param width the width of the rectangle to clear.
* @param height the height of the rectangle to clear.
* @see java.awt.Graphics#fillRect(int, int, int, int)
* @see java.awt.Graphics#drawRect
* @see java.awt.Graphics#setColor(java.awt.Color)
* @see java.awt.Graphics#setPaintMode
* @see java.awt.Graphics#setXORMode(java.awt.Color)
* @since JDK1.0
*/
public abstract void clearRect(int x, int y, int width, int height);
/**
* Draws an outlined round-cornered rectangle using this graphics
* context's current color. The left and right edges of the rectangle
* are at <code>x</code> and <code>x + width</code>,
* respectively. The top and bottom edges of the rectangle are at
* <code>y</code> and <code>y + height</code>.
* @param x the <i>x</i> coordinate of the rectangle to be drawn.
* @param y the <i>y</i> coordinate of the rectangle to be drawn.
* @param width the width of the rectangle to be drawn.
* @param height the height of the rectangle to be drawn.
* @param arcWidth the horizontal diameter of the arc
* at the four corners.
* @param arcHeight the vertical diameter of the arc
* at the four corners.
* @see java.awt.Graphics#fillRoundRect
* @since JDK1.0
*/
public abstract void drawRoundRect(int x, int y, int width, int height,
int arcWidth, int arcHeight);
/**
* Fills the specified rounded corner rectangle with the current color.
* The left and right edges of the rectangle
* are at <code>x</code> and <code>x + width - 1</code>,
* respectively. The top and bottom edges of the rectangle are at
* <code>y</code> and <code>y + height - 1</code>.
* @param x the <i>x</i> coordinate of the rectangle to be filled.
* @param y the <i>y</i> coordinate of the rectangle to be filled.
* @param width the width of the rectangle to be filled.
* @param height the height of the rectangle to be filled.
* @param arcWidth the horizontal diameter
* of the arc at the four corners.
* @param arcHeight the vertical diameter
* of the arc at the four corners.
* @see java.awt.Graphics#drawRoundRect
* @since JDK1.0
*/
public abstract void fillRoundRect(int x, int y, int width, int height,
int arcWidth, int arcHeight);
/**
* Draws a 3-D highlighted outline of the specified rectangle.
* The edges of the rectangle are highlighted so that they
* appear to be beveled and lit from the upper left corner.
* <p>
* The colors used for the highlighting effect are determined
* based on the current color.
* The resulting rectangle covers an area that is
* <code>width + 1</code> pixels wide
* by <code>height + 1</code> pixels tall.
* @param x the <i>x</i> coordinate of the rectangle to be drawn.
* @param y the <i>y</i> coordinate of the rectangle to be drawn.
* @param width the width of the rectangle to be drawn.
* @param height the height of the rectangle to be drawn.
* @param raised a boolean that determines whether the rectangle
* appears to be raised above the surface
* or sunk into the surface.
* @see java.awt.Graphics#fill3DRect
* @since JDK1.0
*/
public void draw3DRect(int x, int y, int width, int height,
boolean raised) {
Color c = getColor();
Color brighter = c.brighter();
Color darker = c.darker();
setColor(raised ? brighter : darker);
drawLine(x, y, x, y + height);
drawLine(x + 1, y, x + width - 1, y);
setColor(raised ? darker : brighter);
drawLine(x + 1, y + height, x + width, y + height);
drawLine(x + width, y, x + width, y + height - 1);
setColor(c);
}
/**
* Paints a 3-D highlighted rectangle filled with the current color.
* The edges of the rectangle will be highlighted so that it appears
* as if the edges were beveled and lit from the upper left corner.
* The colors used for the highlighting effect will be determined from
* the current color.
* @param x the <i>x</i> coordinate of the rectangle to be filled.
* @param y the <i>y</i> coordinate of the rectangle to be filled.
* @param width the width of the rectangle to be filled.
* @param height the height of the rectangle to be filled.
* @param raised a boolean value that determines whether the
* rectangle appears to be raised above the surface
* or etched into the surface.
* @see java.awt.Graphics#draw3DRect
* @since JDK1.0
*/
public void fill3DRect(int x, int y, int width, int height,
boolean raised) {
Color c = getColor();
Color brighter = c.brighter();
Color darker = c.darker();
if (!raised) {
setColor(darker);
}
fillRect(x+1, y+1, width-2, height-2);
setColor(raised ? brighter : darker);
drawLine(x, y, x, y + height - 1);
drawLine(x + 1, y, x + width - 2, y);
setColor(raised ? darker : brighter);
drawLine(x + 1, y + height - 1, x + width - 1, y + height - 1);
drawLine(x + width - 1, y, x + width - 1, y + height - 2);
setColor(c);
}
/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -