com.sun.kjava
Class Graphics

java.lang.Object
  |
  +--com.sun.kjava.Graphics

public class Graphics
extends java.lang.Object

This class contains various methods for drawing on a display. The coordinate system used is such that the points along horizontal axis increase in value from left to right and point along the vertical axis increase in value from top to bottom.


Field Summary
static int AND
          Region copy mode: The copied region is AND'ed with the destination.
static int AND_NOT
          Region copy mode: The copied region is AND'ed with the inverted destination region.
static int ERASE
          Erase mode.
static int GRAY
          Gray drawing mode.
static int INVERT
          Invert mode.
static int NOT
          Region copy mode: The copied region is inverted and overwrites the destination.
static int OFFSCREEN_WINDOW
           
static int ONSCREEN_WINDOW
           
static int OR
          Region copy mode: The copied region is OR'ed with the destination.
static int OVERWRITE
          Region copy mode: The copied region overwrites the destination.
static int PLAIN
          Plain drawing mode.
static int RAISED
          Constant for a slightly raised border.
static int SIMPLE
          Constant for a plain rectangle border.
static int SOUND_ALARM
          System sound for the alarm.
static int SOUND_CLICK
          System sound for a click.
static int SOUND_CONFIRMATION
          System sound for confirmation.
static int SOUND_ERROR
          System sound for error.
static int SOUND_INFO
          System sound for info.
static int SOUND_STARTUP
          System sound for startup.
static int SOUND_WARNING
          System sound for warning.
static int XOR
          Region copy mode: The copied region is XOR'ed with the destination.
 
Method Summary
static int borderType(int cornerDiam, int shadow, int width)
          Constructs a border type.
static void clearScreen()
          Clear the screen.
static void copyOffScreenRegion(int left, int top, int width, int height, int dstX, int dstY, int mode, int srcWind, int dstWind)
          Copy a rectangular region from one place to another, possibly in different windows.
static 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.
static void drawBitmap(int left, int top, Bitmap bitmap)
          Draw a bitmap.
static void drawBorder(int left, int top, int width, int height, int mode, int frameType)
          Draw a rectangular border.
static void drawLine(int srcX, int srcY, int dstX, int dstY, int mode)
          Draw a line.
static void drawRectangle(int left, int top, int width, int height, int mode, int cornerDiam)
          Draw a solid rectangle.
static int drawString(java.lang.String text, int left, int top)
          Draw a string at a given position.
static int drawString(java.lang.String text, int left, int top, int mode)
          Draw a string at a given position.
static Graphics getGraphics()
          There is only ever one Graphics object in the system, and this returns it.
static int getHeight(java.lang.String s)
          Returns the height of a string in pixels.
static int getWidth(java.lang.String s)
          Returns the width of a string in pixels.
static void playSound(int sound)
          Play a system sound.
static void resetDrawRegion()
          Reset the region in which drawing can be performed to be the whole screen.
static void setDrawRegion(int left, int top, int width, int height)
          Set the region in which drawing can be performed.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SIMPLE

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

RAISED

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

PLAIN

public static final int PLAIN
Plain drawing mode.

GRAY

public static final int GRAY
Gray drawing mode.

ERASE

public static final int ERASE
Erase mode.

INVERT

public static final int INVERT
Invert mode.

OVERWRITE

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

AND

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

AND_NOT

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

XOR

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

OR

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

NOT

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

ONSCREEN_WINDOW

public static final int ONSCREEN_WINDOW

OFFSCREEN_WINDOW

public static final int OFFSCREEN_WINDOW

SOUND_INFO

public static final int SOUND_INFO
System sound for info.

SOUND_WARNING

public static final int SOUND_WARNING
System sound for warning.

SOUND_ERROR

public static final int SOUND_ERROR
System sound for error.

SOUND_STARTUP

public static final int SOUND_STARTUP
System sound for startup.

SOUND_ALARM

public static final int SOUND_ALARM
System sound for the alarm.

SOUND_CONFIRMATION

public static final int SOUND_CONFIRMATION
System sound for confirmation.

SOUND_CLICK

public static final int SOUND_CLICK
System sound for a click.
Method Detail

getGraphics

public static Graphics getGraphics()
There is only ever one Graphics object in the system, and this returns it.
Returns:
the single global Graphics context.

drawLine

public static void drawLine(int srcX,
                            int srcY,
                            int dstX,
                            int dstY,
                            int mode)
Draw a line.
Parameters:
srcX - the X coordinate of the starting point
srcY - the Y coordinate of the starting point
dstX - the X coordinate of the destination point
dstY - the Y coordinate of the destination point
mode - the drawing mode to use (one of PLAIN, GRAY, ERASE or INSERT.

drawRectangle

public static void drawRectangle(int left,
                                 int top,
                                 int width,
                                 int height,
                                 int mode,
                                 int cornerDiam)
Draw a solid rectangle.
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.
cornerDiam - the diameter of four imaginary circles used to form the rounded corners. An imaginary circle is placed within each corner tangent to the rectangle on two sides.

drawBorder

public static 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.

borderType

public static 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

drawString

public static int drawString(java.lang.String text,
                             int left,
                             int top,
                             int mode)
Draw a string at a given position. Will draw "null" if text is null.
Parameters:
text - the String to draw
left - the x coordinate of the top left bound of first character.
top - the y coordinate of the top left bound of first character.
mode - the drawing mode to use (one of PLAIN, RAY, ERASE or INVERT.
Returns:
right bound of last character drawn

drawString

public static int drawString(java.lang.String text,
                             int left,
                             int top)
Draw a string at a given position. This method is equivalent to drawString(text, left, top, PLAIN).
Parameters:
text - the String to draw
left - the x coordinate of the top left bound of first character.
top - the y coordinate of the top left bound of first character.
Returns:
the x coordinate of the right bound of last character drawn

getWidth

public static int getWidth(java.lang.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

getHeight

public static int getHeight(java.lang.String s)
Returns the height of a string in pixels.
Parameters:
s - the String to measure
Returns:
the height of the given String in pixels

setDrawRegion

public static void setDrawRegion(int left,
                                 int top,
                                 int width,
                                 int height)
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

resetDrawRegion

public static void resetDrawRegion()
Reset the region in which drawing can be performed to be the whole screen.

copyRegion

public static 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)

copyOffScreenRegion

public static void copyOffScreenRegion(int left,
                                       int top,
                                       int width,
                                       int height,
                                       int dstX,
                                       int dstY,
                                       int mode,
                                       int srcWind,
                                       int dstWind)
Copy a rectangular region from one place to another, possibly in different windows. There is the usual ONSCREEN_WINDOW and a hidden OFFSCREEN_WINDOW of the same size. The OFFSCREEN_WINDOW is handy for storing bitmaps in game programs.
Parameters:
left - the x coordinate of the source region's top left corner
top - the y coordinate of the source region's top left corner
width - the width of the source region
height - the height of the source region
dstX - the x coordinate of the point to which the region should be copied in the destination
dstY - the y coordinate of the point to which the region should be copied in the destination
mode - the copy mode (one of OVERWRITE, AND, AND_NOT, XOR, OR, INVERT)
srcWind - either ONSCREEN_WINDOW or OFFSCREEN_WINDOW
dstWind - either ONSCREEN_WINDOW or OFFSCREEN_WINDOW

clearScreen

public static void clearScreen()
Clear the screen.

drawBitmap

public static 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

playSound

public static void playSound(int sound)
Play a system sound.
Parameters:
sound - one of the SOUND_xxx constants