Class Picture
- java.lang.Object
-
- Picture
-
public class Picture extends java.lang.ObjectA picture from an image file.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidborder(int width)Adds a black border to the image.java.awt.ColorgetColorAt(int x, int y)Gets the color of a pixel.intgetHeight()Gets the height of this picture.intgetWidth()Gets the width of this picture.voidload(java.lang.String source)Loads a picture from a given file or URL.voidmove(int dx, int dy)Moves this picture by a given amount.voidpick()Displays a file chooser for picking a file, loads the picture from the file that the user selected, and pauses so that the user can see the loaded picture.voidscale(int newWidth, int newHeight)Scales this picture to a new size.voidsetColorAt(int x, int y, java.awt.Color c)Sets the color of a pixel.java.lang.StringtoString()
-
-
-
Method Detail
-
load
public void load(java.lang.String source)
Loads a picture from a given file or URL.- Parameters:
source- the filename or URL
-
pick
public void pick()
Displays a file chooser for picking a file, loads the picture from the file that the user selected, and pauses so that the user can see the loaded picture.
-
getWidth
public int getWidth()
Gets the width of this picture.- Returns:
- the width
-
getHeight
public int getHeight()
Gets the height of this picture.- Returns:
- the height
-
move
public void move(int dx, int dy)Moves this picture by a given amount.- Parameters:
dx- the amount by which to move in x-directiondy- the amount by which to move in y-direction
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getColorAt
public java.awt.Color getColorAt(int x, int y)Gets the color of a pixel.- Parameters:
x- the column index (between 0 and getWidth() - 1)y- the row index (between 0 and getHeight() - 1)- Returns:
- the color of the pixel at position (x, y)
-
setColorAt
public void setColorAt(int x, int y, java.awt.Color c)Sets the color of a pixel.- Parameters:
x- the column index (between 0 and getWidth() - 1)y- the row index (between 0 and getHeight() - 1)c- the color for the pixel at position (x, y)
-
scale
public void scale(int newWidth, int newHeight)Scales this picture to a new size.- Parameters:
newWidth- the new width of the picturenewHeight- the new height of the picture
-
border
public void border(int width)
Adds a black border to the image.- Parameters:
width- the border width
-
-