All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.bulletproof.gui.Graphics

java.lang.Object
   |
   +----com.bulletproof.gui.Graphics

public class Graphics
extends Object
Graphics is the abstract base class for all graphics contexts which allow an application to draw onto components realized on various devices or onto off-screen images. A Graphics object encapsulates the state information needed for the various rendering operations that Java supports. This state information includes:

Coordinates are infinitely thin and lie between the pixels of the output device. Operations which draw the outline of a figure operate by traversing along the infinitely thin path with a pixel-sized pen that hangs down and to the right of the anchor point on the path. Operations which fill a figure operate by filling the interior of the infinitely thin path. Operations which render horizontal text render the ascending portion of the characters entirely above the baseline coordinate.

Some important points to consider are that drawing a figure that covers a given rectangle will occupy one extra row of pixels on the right and bottom edges compared to filling a figure that is bounded by that same rectangle. Also, drawing a horizontal line along the same y coordinate as the baseline of a line of text will draw the line entirely below the text except for any descenders. Both of these properties are due to the pen hanging down and to the right from the path that it traverses.

All coordinates which appear as arguments to the methods of this Graphics object are considered relative to the translation origin of this Graphics object prior to the invocation of the method. All rendering operations modify only pixels which lie within the area bounded by both the current clip of the graphics context and the extents of the Component used to create the Graphics object.


Variable Index

 o AND
Region copy mode: The copied region is AND'ed with the destination.
 o AND_NOT
Region copy mode: The copied region is AND'ed with the inverted destination region.
 o ERASE
Erase mode.
 o GRAY
Gray drawing mode.
 o INVERT
Invert mode.
 o NOT
Region copy mode: The copied region is inverted and overwrites the destination.
 o OFFSCREEN_WINDOW
 o ONSCREEN_WINDOW
 o OR
Region copy mode: The copied region is OR'ed with the destination.
 o OVERWRITE
Region copy mode: The copied region overwrites the destination.
 o PLAIN
Plain drawing mode.
 o RAISED
Constant for a slightly raised border.
 o SIMPLE
Constant for a plain rectangle border.
 o SOUND_ALARM
System sound for the alarm.
 o SOUND_CLICK
System sound for a click.
 o SOUND_CONFIRMATION
System sound for confirmation.
 o SOUND_ERROR
System sound for error.
 o SOUND_INFO
System sound for info.
 o SOUND_STARTUP
System sound for startup.
 o SOUND_WARNING
System sound for warning.
 o XOR
Region copy mode: The copied region is XOR'ed with the destination.

Constructor Index

 o Graphics()
Constructs a new Graphics object.

Method Index

 o beep()
Play the default system sound.
 o borderType(int, int, int)
Constructs a border type.
 o clearRect(int, int, int, int)
Clears the specified rectangle by filling it with the background color of the current drawing surface.
 o colorSupported()
Determine whether the platform supports color.
 o copyOffScreenRegion(int, int, int, int, int, int, int, int, int)
 o copyRegion(int, int, int, int, int, int, int)
Copy a rectangular region from one place to another.
 o create(int, int, int, int)
Creates a new Graphics object based on this Graphics object, but with a new translation and clip area.
 o draw3DRect(int, int, int, int, int)
Draw a 3D rectangular border.
 o drawArc(int, int, int, int, int, int)
Draws the outline of an arc covering the specified rectangle, starting at startAngle and extending for arcAngle degrees, using the current color.
 o drawBitmap(int, int, Bitmap)
Draw a bitmap.
 o drawBorder(int, int, int, int, int, int)
Draw a rectangular border.
 o drawCursor(int, int, int, int)
Draws the outline of the specified rectangle using the current color.
 o drawDots(int, int, int, int)
Draws a dotted line between the coordinates (x1,y1) and (x2,y2) using the current color.
 o drawImage(Image, int, int)
Draws an image at the given x and y coordinates.
 o drawLine(int, int, int, int)
Draws a line between the coordinates (x1,y1) and (x2,y2) using the current color.
 o drawPolygon(int[], int[], int)
Draws a sequence of connected lines defined by arrays of x coordinates and y coordinates using the current color.
 o drawRect(int, int, int, int)
Draws the outline of the specified rectangle using the current color.
 o drawRoundRect(int, int, int, int, int, int)
Draws the outline of the specified rounded corner rectangle using the current color.
 o drawString(char[], int, int, int, int)
Draws the specified String using the current font and color.
 o drawString(String, int, int)
Draws the specified String using the current font and color.
 o fill3DRect(int, int, int, int, int)
Draws the outline of the specified rectangle using the current color.
 o fillArc(int, int, int, int, int, int)
Fills an arc bounded by the specified rectangle, starting at startAngle and extending for arcAngle degrees, with the current color.
 o fillPolygon(int[], int[], int)
Fills a sequence of connected lines defined by arrays of x coordinates and y coordinates using the current color.
 o fillRect(int, int, int, int)
Fills the specified rectangle with the current color.
 o fillRoundRect(int, int, int, int, int, int)
Fills the specified rounded corner rectangle with the current color.
 o getFont()
Gets the current font.
 o getFontMetrics()
Gets the font metrics of the current font.
 o getFontMetrics(Font)
Gets the font metrics of the selected font.
 o getHeight()
Returns the height of the current font in pixels.
 o getLocationOnScreen()
Set the region in which drawing can be performed.
 o getScreenDimension()
Get the size of the screen.
 o getWidth(String)
Returns the width of a string in pixels.
 o isColor()
Determine whether the platform is drawing in color.
 o playSound(int)
Play a system sound.
 o playSound(int, int)
Play a tone of the specified frequency for the specified duration.
 o resetDrawRegion()
Reset the region in which drawing can be performed to be the whole screen.
 o setColor(Color)
Sets the current color to the specified color.
 o setDrawRegion(int, int, int, int, Rectangle)
/** Set the region in which drawing can be performed.
 o setFont(Font)
Sets the font for all subsequent text rendering operations.
 o setPaintMode()
Sets the logical pixel operation function to the Paint, or overwrite mode.
 o setXORMode(Color)
Sets the logical pixel operation function to the XOR mode, which alternates pixels between the current color and a new specified XOR alternation color.
 o translate(int, int)
Translates the origin of the graphics context to the point (x, y) in the current coordinate system.

Variables

 o SIMPLE
 public static final int SIMPLE
Constant for a plain rectangle border.

 o RAISED
 public static final int RAISED
Constant for a slightly raised border.

 o PLAIN
 public static final int PLAIN
Plain drawing mode.

 o GRAY
 public static final int GRAY
Gray drawing mode.

 o ERASE
 public static final int ERASE
Erase mode.

 o INVERT
 public static final int INVERT
Invert mode.

 o OVERWRITE
 public static final int OVERWRITE
Region copy mode: The copied region overwrites the destination.

 o AND
 public static final int AND
Region copy mode: The copied region is AND'ed with the destination.

 o AND_NOT
 public static final int AND_NOT
Region copy mode: The copied region is AND'ed with the inverted destination region.

 o XOR
 public static final int XOR
Region copy mode: The copied region is XOR'ed with the destination.

 o OR
 public static final int OR
Region copy mode: The copied region is OR'ed with the destination.

 o NOT
 public static final int NOT
Region copy mode: The copied region is inverted and overwrites the destination.

 o ONSCREEN_WINDOW
 public static final int ONSCREEN_WINDOW
 o OFFSCREEN_WINDOW
 public static final int OFFSCREEN_WINDOW
 o SOUND_INFO
 public static final int SOUND_INFO
System sound for info.

 o SOUND_WARNING
 public static final int SOUND_WARNING
System sound for warning.

 o SOUND_ERROR
 public static final int SOUND_ERROR
System sound for error.

 o SOUND_STARTUP
 public static final int SOUND_STARTUP
System sound for startup.

 o SOUND_ALARM
 public static final int SOUND_ALARM
System sound for the alarm.

 o SOUND_CONFIRMATION
 public static final int SOUND_CONFIRMATION
System sound for confirmation.

 o SOUND_CLICK
 public static final int SOUND_CLICK
System sound for a click.

Constructors

 o Graphics
 public Graphics()
Constructs a new Graphics object. Since Graphics is an abstract class, and since it must be customized by subclasses for different output devices, Graphics objects cannot be created directly. Instead, Graphics objects must be obtained from another Graphics object or created by a Component.

See Also:
getGraphics, create

Methods

 o create
 public Graphics create(int x,
                        int y,
                        int width,
                        int height)
Creates a new Graphics object based on this Graphics object, but with a new translation and clip area. The new Graphics object will have its origin translated to the specified coordinate (x, y) and will also have its current clip intersected with the specified rectangle. The arguments are all interpreted in the coordinate system of the original Graphics object.

Parameters:
x - the x coordinate of the new translation origin and rectangle to intersect the clip with
y - the y coordinate of the new translation origin and rectangle to intersect the clip with
width - the width of the rectangle to intersect the clip with
height - the height of the rectangle to intersect the clip with
See Also:
translate
 o clearRect
 public void clearRect(int x,
                       int y,
                       int w,
                       int h)
Clears the specified rectangle by filling it with the background color of the current drawing surface.

Parameters:
x - the x coordinate of the rectangle to clear
y - the y coordinate of the rectangle to clear
width - the width of the rectangle to clear
height - the height of the rectangle to clear
 o drawLine
 public void drawLine(int x1,
                      int y1,
                      int x2,
                      int y2)
Draws a line between the coordinates (x1,y1) and (x2,y2) using the current color.

Parameters:
x1 - the x coordinate of the start of the line
y1 - the y coordinate of the start of the line
x2 - the x coordinate of the end of the line
y2 - the y coordinate of the end of the line
 o drawDots
 public void drawDots(int x1,
                      int y1,
                      int x2,
                      int y2)
Draws a dotted line between the coordinates (x1,y1) and (x2,y2) using the current color.

Parameters:
x1 - the x coordinate of the start of the line
y1 - the y coordinate of the start of the line
x2 - the x coordinate of the end of the line
y2 - the y coordinate of the end of the line
 o drawPolygon
 public void drawPolygon(int xPoints[],
                         int yPoints[],
                         int nPoints)
Draws a sequence of connected lines defined by arrays of x coordinates and y coordinates using the current color. The figure is not automatically closed if the first coordinate is different from the last coordinate.

Parameters:
xPoints - an array of x points
yPoints - an array of y points
nPoints - the total number of points
 o fillPolygon
 public void fillPolygon(int xPoints[],
                         int yPoints[],
                         int nPoints)
Fills a sequence of connected lines defined by arrays of x coordinates and y coordinates using the current color. The figure is not automatically closed if the first coordinate is different from the last coordinate.

Parameters:
xPoints - an array of x points
yPoints - an array of y points
nPoints - the total number of points
 o drawRoundRect
 public void drawRoundRect(int x,
                           int y,
                           int width,
                           int height,
                           int arcWidth,
                           int arcHeight)
Draws the outline of the specified rounded corner rectangle using the current color. The resulting rectangle will cover an area (width + 1) pixels wide by (height + 1) pixels tall.

Parameters:
x - the x coordinate of the rectangle to be drawn
y - the y coordinate of the rectangle to be drawn
width - the width of the rectangle to be drawn
height - the height of the rectangle to be drawn
arcWidth - the horizontal diameter of the arc at the four corners
arcHeight - the vertical diameter of the arc at the four corners
See Also:
fillRoundRect
 o drawString
 public void drawString(char text[],
                        int start,
                        int len,
                        int x,
                        int y)
Draws the specified String using the current font and color. The x,y position is the starting point of the baseline of the String.

Parameters:
str - the String to be drawn
x - the x coordinate of the baseline of the text
y - the y coordinate of the baseline of the text
 o drawString
 public void drawString(String text,
                        int x,
                        int y)
Draws the specified String using the current font and color. The x,y position is the starting point of the baseline of the String.

Parameters:
str - the String to be drawn
x - the x coordinate of the baseline of the text
y - the y coordinate of the baseline of the text
 o drawRect
 public void drawRect(int x,
                      int y,
                      int width,
                      int height)
Draws the outline of the specified rectangle using the current color.

Parameters:
x - the x coordinate of the rectangle to be drawn
y - the y coordinate of the rectangle to be drawn
width - the width of the rectangle to be drawn
height - the height of the rectangle to be drawn
 o draw3DRect
 public void draw3DRect(int x,
                        int y,
                        int width,
                        int height,
                        int mode)
Draw a 3D rectangular border. The border is drawn around the rectangle specified by the given dimensions.

Parameters:
left - the x coordinate of the rectangle's top left corner
top - the y coordinate of the rectangle's top left corner
width - the width of the rectangle
height - the height of the rectangle
mode - the drawing mode to use (one of GRAY RAISED SIMPLE or INVERT.
 o fill3DRect
 public void fill3DRect(int x,
                        int y,
                        int width,
                        int height,
                        int mode)
Draws the outline of the specified rectangle using the current color.

Parameters:
x - the x coordinate of the rectangle to be drawn
y - the y coordinate of the rectangle to be drawn
width - the width of the rectangle to be drawn
height - the height of the rectangle to be drawn
 o drawCursor
 public void drawCursor(int x,
                        int y,
                        int width,
                        int height)
Draws the outline of the specified rectangle using the current color. The resulting rectangle will cover an area (width + 1) pixels wide by (height + 1) pixels tall.

Parameters:
x - the x coordinate of the rectangle to be drawn
y - the y coordinate of the rectangle to be drawn
width - the width of the rectangle to be drawn
height - the height of the rectangle to be drawn
 o fillRect
 public void fillRect(int x,
                      int y,
                      int width,
                      int height)
Fills the specified rectangle with the current color.

Parameters:
x - the x coordinate of the rectangle to be filled
y - the y coordinate of the rectangle to be filled
width - the width of the rectangle to be filled
height - the height of the rectangle to be filled
 o fillRoundRect
 public void fillRoundRect(int x,
                           int y,
                           int width,
                           int height,
                           int arcWidth,
                           int arcHeight)
Fills the specified rounded corner rectangle with the current color.

Parameters:
x - the x coordinate of the rectangle to be filled
y - the y coordinate of the rectangle to be filled
width - the width of the rectangle to be filled
height - the height of the rectangle to be filled
arcWidth - the horizontal diameter of the arc at the four corners
arcHeight - the vertical diameter of the arc at the four corners
 o getFont
 public Font getFont()
Gets the current font.

 o getFontMetrics
 public FontMetrics getFontMetrics()
Gets the font metrics of the current font.

 o getFontMetrics
 public FontMetrics getFontMetrics(Font font)
Gets the font metrics of the selected font.

 o colorSupported
 public static boolean colorSupported()
Determine whether the platform supports color. Used only to determine if a 3D GUI should be drawn

 o isColor
 public static boolean isColor()
Determine whether the platform is drawing in color.

 o setColor
 public void setColor(Color c)
Sets the current color to the specified color. All subsequent rendering operations will use this specified color.

Parameters:
c - the new rendering color
 o setFont
 public void setFont(Font font)
Sets the font for all subsequent text rendering operations.

Parameters:
font - the specified font
 o setPaintMode
 public void setPaintMode()
Sets the logical pixel operation function to the Paint, or overwrite mode. All subsequent rendering operations will overwrite the destination with the current color.

 o setXORMode
 public void setXORMode(Color c2)
Sets the logical pixel operation function to the XOR mode, which alternates pixels between the current color and a new specified XOR alternation color. When subsequent rendering operations are performed on top of pixels which are the specified XOR alternation color, they will be changed to the current color and vice versa. Drawing an image on a region of pixels of the specified XOR alternation color will also change those pixels to the colors in the image. Drawing on pixels of other colors will not necessarily result in a predictable final color but all rendering operations will always be reversible in this mode; if you draw the same figure twice then all pixels will be restored to their original values.

Parameters:
c1 - the XOR alternation color
 o translate
 public void translate(int x,
                       int y)
Translates the origin of the graphics context to the point (x, y) in the current coordinate system. All coordinates used in subsequent rendering operations on this graphics context will be relative to this new origin.

Parameters:
x - the x coordinate of the new translation origin
y - the y coordinate of the new translation origin
 o setDrawRegion
 public void setDrawRegion(int left,
                           int top,
                           int width,
                           int height,
                           Rectangle masterDrawRegion)
/** Set the region in which drawing can be performed. If the specified region is null then the region is set to be the entire window.

Parameters:
left - the x coordinate of the top left position of the region
left - the y coordinate of the top left position of the region
width - the width of the region
height - the height of the region
 o getLocationOnScreen
 public Point getLocationOnScreen()
Set the region in which drawing can be performed. If the specified region is null then the region is set to be the entire window.

Parameters:
left - the x coordinate of the top left position of the region
left - the y coordinate of the top left position of the region
width - the width of the region
height - the height of the region
 o resetDrawRegion
 public void resetDrawRegion()
Reset the region in which drawing can be performed to be the whole screen.

 o drawImage
 public void drawImage(Image image,
                       int x,
                       int y)
Draws an image at the given x and y coordinates.

 o copyRegion
 public void copyRegion(int left,
                        int top,
                        int width,
                        int height,
                        int dstX,
                        int dstY,
                        int mode)
Copy a rectangular region from one place to another.

Parameters:
left - the x coordinate of the region's top left corner
top - the y coordinate of the region's top left corner
width - the width of the region
height - the height of the region
dstX - the x coordinate of the point to which the region should be copied
dstY - the y coordinate of the point to which the region should be copied
mode - the copy mode (one of OVERWRITE, AND, AND_NOT, XOR, OR, INVERT)
 o copyOffScreenRegion
 public void copyOffScreenRegion(int left,
                                 int top,
                                 int width,
                                 int height,
                                 int dstX,
                                 int dstY,
                                 int mode,
                                 int srcWind,
                                 int dstWind)
 o getScreenDimension
 public static Dimension getScreenDimension()
Get the size of the screen.

 o drawBitmap
 public void drawBitmap(int left,
                        int top,
                        Bitmap bitmap)
Draw a bitmap.

Parameters:
left - the x coordinate of the bitmap's top left corner
top - the y coordinate of the bitmap's top left corner
bitmap - the bitmap to be drawn
 o drawBorder
 public void drawBorder(int left,
                        int top,
                        int width,
                        int height,
                        int mode,
                        int frameType)
Draw a rectangular border. The border is drawn around the rectangle specified by the given dimensions.

Parameters:
left - the x coordinate of the rectangle's top left corner
top - the y coordinate of the rectangle's top left corner
width - the width of the rectangle
height - the height of the rectangle
mode - the drawing mode to use (one of PLAIN, GRAY, ERASE or INSERT.
frameType - one of SIMPLE, RAISED or a type constructed by a call to borderType.
 o borderType
 public int borderType(int cornerDiam,
                       int shadow,
                       int width)
Constructs a border type.

Parameters:
cornerDiam - the diameter of four imaginary circles used to form rounded corners. Must be in the range 0..38.
shadow - the width of a shadow. Must be in the range 0..3.
width - width of the border.Must be in the range 0..3.
Returns:
a value representing the specified type
 o drawArc
 public void drawArc(int x,
                     int y,
                     int width,
                     int height,
                     int startAngle,
                     int arcAngle)
Draws the outline of an arc covering the specified rectangle, starting at startAngle and extending for arcAngle degrees, using the current color. The angles are interpreted such that 0 degrees is at the 3-o'clock position, and positive values indicate counter-clockwise rotations while negative values indicate clockwise rotations. The resulting arc will cover an area (width + 1) pixels wide by (height + 1) pixels tall.

Parameters:
x - the x coordinate of the upper left corner of the arc to be drawn
y - the y coordinate of the upper left corner of the arc to be drawn
width - the width of the arc to be drawn
height - the height of the arc to be drawn
startAngle - the beginning angle
arcAngle - the angular extent of the arc (relative to startAngle)
See Also:
fillArc
 o fillArc
 public void fillArc(int x,
                     int y,
                     int width,
                     int height,
                     int startAngle,
                     int arcAngle)
Fills an arc bounded by the specified rectangle, starting at startAngle and extending for arcAngle degrees, with the current color. This method generates a pie shape. The angles are interpreted such that 0 degrees is at the 3-o'clock position, and positive values indicate counter-clockwise rotations while negative values indicate clockwise rotations.

Parameters:
x - the x coordinate of the upper left corner of the arc to be filled
y - the y coordinate of the upper left corner of the arc to be filled
width - the width of the arc to be filled
height - the height of the arc to be filled
startAngle - the beginning angle
arcAngle - the angular extent of the arc (relative to startAngle).
See Also:
drawArc
 o getWidth
 public int getWidth(String s)
Returns the width of a string in pixels.

Parameters:
s - the String to measure
Returns:
the width of the given String in pixels
 o getHeight
 public int getHeight()
Returns the height of the current font in pixels.

Returns:
the height of the current font in pixels.
 o playSound
 public void playSound(int sound)
Play a system sound.

Parameters:
sound - one of the SOUND_xxx constants
 o beep
 public void beep()
Play the default system sound.

 o playSound
 public void playSound(int freq,
                       int duration)
Play a tone of the specified frequency for the specified duration.


All Packages  Class Hierarchy  This Package  Previous  Next  Index