|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object Mosaic
The class Mosaic makes available a window made up of a grid of colored rectangles. Routines are provided for opening and closing the window and for setting and testing the color of rectangles in the grid. Each rectangle in the grid has a color. The color can be specified by red, green, and blue amounts in the range from 0 to 255. (It can also be given as an object belonging to the class Color.) David Eck (eck@hws.edu), 3 February 2000. Modified October 2005 to use Javadoc comments and to place the window in the center of the screen when it opens.
Constructor Summary | |
Mosaic()
|
Method Summary | |
static void |
close()
Closes the Mosaic window. |
static void |
delay(int milliseconds)
Inserts a pause into the excution of the program. |
static void |
fill(java.awt.Color c)
Set all rectangles in the grid to a specified color. |
static void |
fill(int red,
int green,
int blue)
Set all rectangles in the grid to a specified color. |
static void |
fillRandomly()
Sets each rectangle in the grid to its own randomly selected color. |
static int |
getBlue(int row,
int col)
Get the blue component color of a specified rectangle in the grid. |
static java.awt.Color |
getColor(int row,
int col)
Get the color of a specified rectangle in the grid. |
static int |
getGreen(int row,
int col)
Get the green component color of a specified rectangle in the grid. |
static int |
getRed(int row,
int col)
Get the red component color of a specified rectangle in the grid. |
static boolean |
isOpen()
Test whether the Mosaic window is currently open |
static void |
open()
Open a mosaic window with a 20-by-20 grid of squares, where each square is 15 pixels on a side. |
static void |
open(int rows,
int columns)
Open a mosaic window with the specified numbers or rows and columns of squares, where each square is 15 pixels on a side. |
static void |
open(int rows,
int columns,
int blockWidth,
int blockHeight)
Open a window that shows a mosaic with the specified number of rows and columns of rectangles. |
static void |
setColor(int row,
int col,
java.awt.Color c)
Set the color of a specified rectangle in the grid. |
static void |
setColor(int row,
int col,
int red,
int green,
int blue)
Set the color of a specified rectangle in the grid. |
static void |
setTitle(java.lang.String title)
Change the title displayed in the titlebar of the mosaic window. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Mosaic()
Method Detail |
public static void open()
public static void open(int rows, int columns)
rows
- the number of rows of squares in the gridcolumns
- the numbe of columns of squares in the gridpublic static void open(int rows, int columns, int blockWidth, int blockHeight)
rows
- the number of rows of squares in the gridcolumns
- the numbe of columns of squares in the gridblockWidth
- the width of each rectangle, in pixelsblockHeight
- the height of each rectangle, in pixelspublic static void close()
public static boolean isOpen()
public static void delay(int milliseconds)
milliseconds
- the delay time, in milliseconds. One second is 1000 milliseconds.
If the value of this parameter is less than or equal to zero, the method has no effect.public static void setTitle(java.lang.String title)
title
- the new title for the window. If title is null, then the original
title, "Mosaic Window", is restored.public static java.awt.Color getColor(int row, int col)
row
- the row number of the rectangle whose color is being testedcol
- the column number of the rectangle whose color is being tested
public static int getRed(int row, int col)
row
- the row number of the rectangle whose color is being testedcol
- the column number of the rectangle whose color is being tested
public static int getGreen(int row, int col)
row
- the row number of the rectangle whose color is being testedcol
- the column number of the rectangle whose color is being tested
public static int getBlue(int row, int col)
row
- the row number of the rectangle whose color is being testedcol
- the column number of the rectangle whose color is being tested
public static void setColor(int row, int col, java.awt.Color c)
row
- the row number of the rectangle whose color is being setcol
- the column number of the rectangle whose color is being setc
- the new color for the rectangle in the specified row and column. If c is null, then
the color will be black.public static void setColor(int row, int col, int red, int green, int blue)
row
- the row number of the rectangle whose color is being setcol
- the column number of the rectangle whose color is being setred
- the red component of the color, in the range 0 to 255. The value is clamped to this range;
that is, a value less than 0 is replaced by 0 and a value less than 255 is replaced by 255.green
- the green component of the color, in the range 0 to 255. The value is clamped to this range.blue
- the blue component of the color, in the range 0 to 255. The value is clamped to this range.public static void fill(java.awt.Color c)
c
- the color for all the rectangles. If c is null, black is used.public static void fill(int red, int green, int blue)
red
- the red component of the color, in the range 0 to 255. The value is clamped to this range;
that is, a value less than 0 is replaced by 0 and a value less than 255 is replaced by 255.green
- the green component of the color, in the range 0 to 255. The value is clamped to this range.blue
- the blue component of the color, in the range 0 to 255. The value is clamped to this range.public static void fillRandomly()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |