public final class Picture extends java.lang.Object implements java.awt.event.ActionListener
By default, pixel (x, y) is column x, row y, where (0, 0) is upper left. The method setOriginLowerLeft() change the origin to the lower left.
For additional documentation, see Section 3.1 of Introduction to Programming in Java: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne.
Constructor and Description |
---|
Picture(java.io.File file)
Create a picture by reading in a .png, .gif, or .jpg from a File.
|
Picture(int w,
int h)
Create a blank w-by-h picture, where each pixel is black.
|
Picture(Picture pic)
Copy constructor.
|
Picture(java.lang.String filename)
Create a picture by reading in a .png, .gif, or .jpg from
the given filename or URL name.
|
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(java.awt.event.ActionEvent e)
Opens a save dialog box when the user selects "Save As" from the menu.
|
boolean |
equals(java.lang.Object obj)
Is this Picture equal to obj?
|
java.awt.Color |
get(int i,
int j)
Return the color of pixel (i, j).
|
javax.swing.JLabel |
getJLabel()
Return a JLabel containing this Picture, for embedding in a JPanel,
JFrame or other GUI widget.
|
int |
height()
Return the height of the picture in pixels.
|
static void |
main(java.lang.String[] args)
Test client.
|
void |
save(java.io.File file)
Save the picture to a file in a standard image format.
|
void |
save(java.lang.String name)
Save the picture to a file in a standard image format.
|
void |
set(int i,
int j,
java.awt.Color c)
Set the color of pixel (i, j) to c.
|
void |
setOriginLowerLeft()
Set the origin to be the lower left pixel.
|
void |
setOriginUpperLeft()
Set the origin to be the upper left pixel.
|
void |
show()
Display the picture in a window on the screen.
|
int |
width()
Return the width of the picture in pixels.
|
public Picture(int w, int h)
public Picture(Picture pic)
public Picture(java.lang.String filename)
public Picture(java.io.File file)
public javax.swing.JLabel getJLabel()
public void setOriginUpperLeft()
public void setOriginLowerLeft()
public void show()
public int height()
public int width()
public java.awt.Color get(int i, int j)
public void set(int i, int j, java.awt.Color c)
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public void save(java.lang.String name)
public void save(java.io.File file)
public void actionPerformed(java.awt.event.ActionEvent e)
actionPerformed
in interface java.awt.event.ActionListener
public static void main(java.lang.String[] args)