Supplementary class documentation

Clock class
Color class
Convert class
Graphics class
GraphicsWindow class
InputFile class

The Clock class

Provides methods relating to clocking time. You must import the pgss library to use this class.

static void sleep(int millis)
Waits for millis milliseconds and then returns.

The Color class

Represents a particular color. Notice that many of the colors are already represented by this class: Color.red, for example, is a Color object representing the color red.

You must import the java.awt package to use this class.

static Color black
The color black.

static Color blue
The color blue.

static Color green
The color green.

static Color red
The color red.

static Color white
The color white.

static Color yellow
The color yellow.

The Convert class

Provides methods for converting between various types. You must import the pgss library to use this class.

static double toDouble(int val)
Returns the nearest double value to val.

static double toDouble(String val)
Returns the double value represented in val. If val is not formatted correctly, the method returns Double.MIN_VALUE.

static int toInt(double val)
Returns the nearest integer value to val.

static int toInt(String val)
Returns the integer value represented in val. If val is not formatted correctly, the method returns Integer.MIN_VALUE.

static String toString(double val)
Returns a string representation of val.

static String toString(int val)
Returns a string representation of val.

The Graphics class

Maintains information about the current drawing context. You use this object whenever you wish to draw graphics.

In the coordinate system used here, the first coordinate gives the column , and the second coordinate gives the row. The top left pixel of the canvas is (0,0), and coordinates increase as you move right and downward.

You must import the java.awt package to use this class.

void setColor(Color color)
Sets the current foreground color for this Graphics object.

void drawLine(int x0, int y0, int x1, int y1)
Draws a line from the point (x0, y0) to the point (x1, y1). (Coordinates are numbered beginning with (0,0) at the top left corner and increasing down and to the right.)

void drawOval(int x, int y, int width, int height)
Draws the outline of an oval whose rectangular boundary begins at the top left corner (x, y) and extends width pixels to the right and height pixels down. (Coordinates are numbered beginning with (0,0) at the top left corner and increasing down and to the right.)

void fillOval(int x, int y, int width, int height)
Draws a filled oval whose rectangular boundary begins at the top left corner (x, y) and extends width pixels to the right and height pixels down. (Coordinates are numbered beginning with (0,0) at the top left corner and increasing down and to the right.)

void drawRect(int x, int y, int width, int height)
Draws the outline of a rectangle whose top left corner is at (x, y) and extends width pixels to the right and height pixels down. (Coordinates are numbered beginning with (0,0) at the top left corner and increasing down and to the right.)

void fillRect(int x, int y, int width, int height)
Draws a filled rectangle whose top left corner is at (x, y) and extends width pixels to the right and height pixels down. (Coordinates are numbered beginning with (0,0) at the top left corner and increasing down and to the right.)

void drawString(String str, int x, int y)
Draws text into the canvas, with the baseline starting at the point (x, y) and proceeding right. (Coordinates are numbered beginning with (0,0) at the top left corner and increasing down and to the right.)

The GraphicsWindow class

Provides a window with a blank canvas into which a program might draw. For many features of the window, you'll have to extend this class and override the methods. You need to do this, for example, if you want to add your own menu items.

You must import the pgss library to use this class.

GraphicsWindow()
(Constructor method) Creates new GraphicsWindow whose canvas is 200 pixels in height and width.

int getWidth()
Returns the width in pixels of the drawing area.

int getHeight()
Returns the height in pixels of the drawing area.

Graphics getGraphics()
Returns a Graphics object that you can use for drawing in the drawing area.

void clearAll()
Clears everything from the drawable area.

void repaint()
Schedules the frame for repainting.

void mouseDragging(int x0, int y0, int x1, int y1)
Handles the event when the mouse button is pressed at location (x0,y0) in the drawing area, is currently at (x1,y1), and has not yet been released. This method will be called repeatedly; when the user releases the mouse, the mouseDragged() method is called. By default the mouseDragging() method does nothing, but you can define it in your class to do something useful.

void mouseDragged(int x0, int y0, int x1, int y1) }
Handles the event when the mouse button is pressed at location (x0,y0) in the drawing area and subsequently released at location (x1,y1). By default this does nothing, but you can define it in your class to do something useful.

void keyPressed(char c) }
Handles the event when a keyboard key is pressed. By default this does nothing, but you can define it in your class to do something useful.

void show()
Shows the window to the user. You should call this to start the graphics interface.

void dispose()
Removes the window from the screen.

void setTitle(String title)
Sets the title appearing in the title bar.

void addMenu(String title)
Adds a menu with the given title into the window's menu bar.

void addMenuItem(String menu, String title)
Adds a menu item titled as in the second parameter into the menu whose title is as specified in the first parameter. When this menu item is selected, the menuItemSelected() method is called. You will want to override this method if you want the menu item to do something useful.

void menuItemSelected(String title) }
Handles the event when the user selects an item of the given title from a menu. By default this does nothing, but you can define it in your class to do something useful.

The InputFile class

Provides a class to represent a file that has been opened for reading. You must import the pgss library to use this class.

InputFile(String filename)
(Constructor method) Opens the file filename for input.

void close()
Closes the file.

String readLine()
Returns the next line found in the file. Any terminating end-of-line characters are omitted.

char readChar()
Returns the next character found in the file. This will be '\n' when the user reaches the end of a line.

int readInt()
Returns the next integer found in the file, skipping any whitespace characters. If the next non-whitespace letters don't appear to represent an integer, it eats a single non-whitespace character and returns Integer.MIN_VALUE.

double readDouble()
Returns the next real number found in the file, skipping any whitespace characters. It supports both regular doubles (like 6.1 or -4) and scientific notation (like 3e8). If the next non-whitespace characters don't appear to represent a real number, it eats a single non-whitespace character and returns Double.NaN.

boolean readBoolean()
Returns the next Boolean value found in the file, skipping any whitespace characters. This will be true if the next word of the file is ``true'' (case is insignificant here). If the next non-whitespace letters don't appear to represent a Boolean, it return false.

String readString()
Returns the next string of non-whitespace characters found in the file.