-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathImageRead.java
More file actions
57 lines (40 loc) · 1.02 KB
/
ImageRead.java
File metadata and controls
57 lines (40 loc) · 1.02 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
48
49
50
51
52
53
54
55
56
57
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.swing.*;
import javax.imageio.ImageIO;
import java.io.File;
public class ImageRead extends JPanel{
private BufferedImage image;
JMenuBar menuBar;
public ImageRead()
{
this.image = null;
setFocusable(true);
setLayout(null);
setOpaque(true);
}
/** Sets the main Image **/
public void setImage(BufferedImage image){
this.image = image;
repaint();
}
/** returns the image
* @return The image shown by this panel
*/
public BufferedImage getImage(){
return image;
}
/** Overwritten paint event for drawing **/
public void paintComponent(Graphics g) {
g.setColor(new Color(50,50,50));
g.fillRect(0,0,getSize().width,getSize().height);
if(image != null){
int center_x = getSize().width/2 - image.getWidth() /2;
int center_y = getSize().height/2 - image.getHeight() /2;
if(center_x < 10){ center_x = 10;}
if(center_y < 10){ center_y = 10;}
g.drawImage(image,center_x,center_y,null);
}
}
}