📄 graphics.java
字号:
Color tmp = tl; tl = br; br = tmp; } int x1 = x; int y1 = y; int x2 = x + width; int y2 = y + height; setColor(tl); drawLine(x1, y1, x2, y1); drawLine(x1, y2, x1, y1); setColor(br); drawLine(x2, y1, x2, y2); drawLine(x2, y1, x1, y2); setColor(color);}/** * Fills the specified rectangle with a 3D effect * * @param x The X coordinate of the upper left corner of the fill rect. * @param y The Y coordinate of the upper left corner of the fill rect. * @param width The width of the fill rect. * @param height The height of the fill rect. * @param raised <code>true</code> if the rectangle appears raised, * <code>false</code> if it should appear etched. */public voidfill3DRect(int x, int y, int width, int height, boolean raised){ fillRect(x, y, width, height); draw3DRect(x, y, width-1, height-1, raised);}/*************************************************************************//** * Draws the outline of the specified rectangle with a 3D effect * * @param x The X coordinate of the upper left corner of the draw rect. * @param y The Y coordinate of the upper left corner of the draw rect. * @param width The width of the draw rect. * @param height The height of the draw rect. * @param raised <code>true</code> if the rectangle appears raised, * <code>false</code> if it should appear etched. */public voiddrawRoundRect(int x, int y, int width, int height, boolean raised){ // FIXME: ???}/*************************************************************************//** * Draws an oval that just fits within the specified rectangle. * * @param x The X coordinate of the upper left corner of the rect. * @param y The Y coordinate of the upper left corner of the rect. * @param width The width of the rect. * @param height The height of the rect. */public abstract voiddrawOval(int x, int y, int width, int height);/*************************************************************************//** * Fills an oval that just fits within the specified rectangle. * * @param x The X coordinate of the upper left corner of the rect. * @param y The Y coordinate of the upper left corner of the rect. * @param width The width of the rect. * @param height The height of the rect. */public abstract voidfillOval(int x, int y, int width, int height);/*************************************************************************//** * Draws an arc using the specified bounding rectangle and the specified * angle parameter. The arc is centered at the center of the rectangle. * The arc starts at the arcAngle position and extend for arcAngle * degrees. The degree origin is at the 3 o'clock position. * * @param x The X coordinate of the upper left corner of the rect. * @param y The Y coordinate of the upper left corner of the rect. * @param width The width of the rect. * @param height The height of the rect. * @param arcStart The beginning angle of the arc. * @param arcAngle The extent of the arc. */public abstract voiddrawArc(int x, int y, int width, int height, int startAngle, int arcAngle);/*************************************************************************//** * Fills the arc define by the specified bounding rectangle and the specified * angle parameter. The arc is centered at the center of the rectangle. * The arc starts at the arcAngle position and extend for arcAngle * degrees. The degree origin is at the 3 o'clock position. * * @param x The X coordinate of the upper left corner of the rect. * @param y The Y coordinate of the upper left corner of the rect. * @param width The width of the rect. * @param height The height of the rect. * @param arcStart The beginning angle of the arc. * @param arcAngle The extent of the arc. */public abstract voidfillArc(int x, int y, int width, int height, int startAngle, int arcAngle);/*************************************************************************//** * Draws a series of interconnected lines determined by the arrays * of corresponding x and y coordinates. * * @param xPoints The X coordinate array. * @param yPoints The Y coordinate array. * @param npoints The number of points to draw. */public abstract voiddrawPolyline(int xPoints[], int yPoints[], int npoints);/*************************************************************************//** * Draws a series of interconnected lines determined by the arrays * of corresponding x and y coordinates. The figure is closed if necessary * by connecting the first and last points. * * @param xPoints The X coordinate array. * @param yPoints The Y coordinate array. * @param npoints The number of points to draw. */public abstract voiddrawPolygon(int xPoints[], int yPoints[], int npoints);/*************************************************************************//** * Draws the specified polygon. * * @param polygon The polygon to draw. */public voiddrawPolygon(Polygon polygon){ drawPolygon(polygon.xpoints, polygon.ypoints, polygon.npoints);}/*************************************************************************//** * Fills the polygon determined by the arrays * of corresponding x and y coordinates. * * @param xPoints The X coordinate array. * @param yPoints The Y coordinate array. * @param npoints The number of points to draw. */public abstract voidfillPolygon(int xPoints[], int yPoints[], int npoints);/*************************************************************************//** * Fills the specified polygon * * @param polygon The polygon to fill. */public voidfillPolygon(Polygon polygon){ fillPolygon(polygon.xpoints, polygon.ypoints, polygon.npoints);}/*************************************************************************//** * Draws the specified string starting at the specified point. * * @param string The string to draw. * @param x The X coordinate of the point to draw at. * @param y The Y coordinate of the point to draw at. */public abstract voiddrawString(String string, int x, int y);/*************************************************************************//** * Draws the specified characters starting at the specified point. * * @param data The array of characters to draw. * @param offset The offset into the array to start drawing characters from. * @param length The number of characters to draw. * @param x The X coordinate of the point to draw at. * @param y The Y coordinate of the point to draw at. */public voiddrawChars(char data[], int offset, int length, int x, int y){ drawString(new String(data, offset, length), x, y);}/*************************************************************************//** * Draws the specified bytes as text starting at the specified point. * * @param data The array of bytes to draw. * @param offset The offset into the array to start drawing bytes from. * @param length The number of bytes to draw. * @param x The X coordinate of the point to draw at. * @param y The Y coordinate of the point to draw at. */public voiddrawChars(byte data[], int offset, int length, int x, int y){ drawString(new String(data, offset, length), x, y);}/*public abstract void drawString(AttributedCharacterIterator iterator, int x, int y)*/public voiddrawBytes(byte[] data, int offset, int length, int x, int y){ String str = new String(data, offset, length); drawString(str, x, y);}/*************************************************************************//** * Draws all of the image that is available and returns. If the image * is not completely loaded, <code>false</code> is returned and * the specified iamge observer is notified as more data becomes * available. * * @param image The image to draw. * @param x The X coordinate of the point to draw at. * @param y The Y coordinate of the point to draw at. * @param observer The image observer to notify as data becomes available. * * @return <code>true</code> if all the image data is available, * <code>false</code> otherwise. */public abstract booleandrawImage(Image image, int x, int y, ImageObserver observer); /*************************************************************************//** * Draws all of the image that is available and returns. The image * is scaled to fit in the specified rectangle. If the image * is not completely loaded, <code>false</code> is returned and * the specified iamge observer is notified as more data becomes * available. * * @param image The image to draw. * @param x The X coordinate of the point to draw at. * @param y The Y coordinate of the point to draw at. * @param width The width of the rectangle to draw in. * @param height The height of the rectangle to draw in. * @param observer The image observer to notify as data becomes available. * * @return <code>true</code> if all the image data is available, * <code>false</code> otherwise. */public abstract booleandrawImage(Image image, int x, int y, int width, int height, ImageObserver observer); /*************************************************************************//** * Draws all of the image that is available and returns. If the image * is not completely loaded, <code>false</code> is returned and * the specified iamge observer is notified as more data becomes * available. * * @param image The image to draw. * @param x The X coordinate of the point to draw at. * @param y The Y coordinate of the point to draw at. * @param bgcolor The background color to use for the image. * @param observer The image observer to notify as data becomes available. * * @return <code>true</code> if all the image data is available, * <code>false</code> otherwise. */public abstract booleandrawImage(Image image, int x, int y, Color bgcolor, ImageObserver observer); /*************************************************************************//** * Draws all of the image that is available and returns. The image * is scaled to fit in the specified rectangle. If the image * is not completely loaded, <code>false</code> is returned and * the specified iamge observer is notified as more data becomes * available. * * @param image The image to draw. * @param x The X coordinate of the point to draw at. * @param y The Y coordinate of the point to draw at. * @param width The width of the rectangle to draw in. * @param height The height of the rectangle to draw in. * @param bgcolor The background color to use for the image. * @param observer The image observer to notify as data becomes available. * * @return <code>true</code> if all the image data is available, * <code>false</code> otherwise. */public abstract booleandrawImage(Image image, int x, int y, int width, int height, Color bgcolor, ImageObserver observer); /*************************************************************************//** * FIXME: Write Javadocs for this when you understand it. */public abstract booleandrawImage(Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer);/*************************************************************************//** * FIXME: Write Javadocs for this when you understand it. */public abstract booleandrawImage(Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer);/*************************************************************************//** * Free any resources held by this graphics context immediately instead * of waiting for the object to be garbage collected and finalized. */public abstract voiddispose();/*************************************************************************//** * Frees the resources held by this graphics context when it is * garbage collected. */public voidfinalize(){ dispose();}/*************************************************************************//** * Returns a string representation of this object. * * @param A string representation of this object. */public StringtoString(){ return(super.toString());}public booleanhitClip(int x, int y, int width, int height){ throw new UnsupportedOperationException("not implemented yet");}public RectanglegetClipBounds(Rectangle r){ Rectangle clipBounds = getClipBounds(); if (r == null) return clipBounds; r.x = clipBounds.x; r.y = clipBounds.y; r.width = clipBounds.width; r.height = clipBounds.height; return r;}} // class Graphics
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -