-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImagePanel.java
More file actions
47 lines (39 loc) · 1.16 KB
/
ImagePanel.java
File metadata and controls
47 lines (39 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
/**
* Write a description of class ImagePanel here.
*
* @author (Omar Farooq)
* @version (a version number or a date)
*/
public class ImagePanel extends JPanel {
private BufferedImage image;
public ImagePanel(){
//default constructor
}
public ImagePanel(String filename) {
try {
image = ImageIO.read(new File(filename));
} catch (IOException ex) {
System.err.println("Image not found");
}
}
public void setImage (String filename){
try {
image = ImageIO.read(new File(filename));
} catch (IOException ex) {
System.err.println("Image not found");
}
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if (image!=null)g.drawImage(image, 0, 0, null); // see javadoc for more info on the parameters
}
}