Objects and Methods Summary


[Page 126 (continued)]

In this chapter, we talk about several kinds of encodings of data (or objects).

Color

An object that holds red, green, and blue values, each between 0 and 255.

Picture

Pictures are encodings of images, typically coming from a JPEG file or a bitmap (.bmp) file.

Pixel

A pixel is a dot in a Picture object. It has a color (red, green, and blue) and an (x, y) position associated with it. It remembers its own Picture object so that a change to the pixel changes the real dot in the picture.


Picture Methods

getHeight()

This method returns the height of the Picture object in pixels.

getPixel(int x, int y)

This method takes an x position and a y position (two numbers), and returns the Pixel object at that location in the Picture object it is invoked on.

getPixels()

Returns a one-dimensional array of Pixel objects in the Picture object it is invoked on.

getWidth()

This method returns the width of the Picture object in pixels.

writePictureTo(String fileName)

This method takes a file name (a string) as input, then writes the Picture object to the file as a JPEG. (Be sure to end the filename in ".jpg" or ".bmp" for the operating system to understand it well.)



[Page 127]

Pixel Methods

getColor()

Returns the Color object for the Pixel object.

getred(), getGreen(), getBlue()

Each method returns the value (between 0 and 255) of the amount of redness, greenness, and blueness (respectively) in the Pixel object.

getX(), getY()

This method returns the x or y (respectively) position of where that Pixel object is in the picture.

setColor(Color color)

This method takes a Color object and sets the color for the Pixel object.

setRed(int value), setGreen(int value), setBlue(int value)

Each method takes a value (between 0 and 255) and sets the redness, greenness, or blueness (respectively) of the Pixel object to the given value.


Color Methods

new Color(int red,int green, int blue)

Takes three inputs: the red, green, and blue values (in that order), then creates and returns a Color object.

darker(),brighter()

The methods return a slightly darker or lighter (respectively) version of the Color object.


ColorChooser Methods

ColorChooser.pickAColor()

Displays a window with ways to pick a color. Find the color you want, and the method will return the Color object that you picked.


There are a bunch of constants that are useful in this chapter. These are variables with pre-defined values. These values are colors: Color.black, Color.white, Color.blue, Color.red, Color.green, Color.gray, Color.darkGray, Color.pink, Color.yellow, Color.orange, Color.lightGray, Color.magenta, Color.cyan. You can also use Color.BLACK, Color.WHITE, and so on. Notice that these are not method calls but are public class variables (fields) so they can be accessed using ClassName.fieldName.



Introduction to Computing & Programming Algebra in Java(c) A Multimedia Approach
Introduction to Computing & Programming Algebra in Java(c) A Multimedia Approach
ISBN: N/A
EAN: N/A
Year: 2007
Pages: 191

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net