-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImage_Panel.java
53 lines (42 loc) · 1.36 KB
/
Image_Panel.java
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
48
49
50
51
52
53
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.awt.Graphics;
import javax.swing.JPanel;
public class Image_Panel extends JPanel
{
private boolean image_initialized = false;
private BufferedImage img = null;
protected static final Dimension DEFAULT_DIMENSION = new Dimension( 100, 100 );
public Image_Panel()
{
this.setPreferredSize( Image_Panel.DEFAULT_DIMENSION );
}
public void Set_Image( BufferedImage new_image )
{
if ( new_image != null ) {
img = new_image;
image_initialized = true;
this.setPreferredSize( new Dimension(this.img.getWidth(), this.img.getHeight() ) );
} else {
image_initialized = false;
this.setPreferredSize( Image_Panel.DEFAULT_DIMENSION );
}
repaint();
}
// // this function is never called
// public void Draw_Again()
// {
// repaint();
// }
// // this function is never called
// @Override
// public void paintComponent(Graphics g)
// {
// super.paintComponent(g);
// if ( image_initialized ) {
// g.drawImage(img, 0, 0, null );
// } else {
// g.drawString("No image selected", (int)(this.getWidth()/2-50), (int)(this.getHeight()/2-10) );
// }
// }
}