-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoadImageApp.java
More file actions
49 lines (40 loc) · 1.17 KB
/
LoadImageApp.java
File metadata and controls
49 lines (40 loc) · 1.17 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
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;
public class LoadImageApp extends Component {
BufferedImage img;
public void paint(Graphics g) {
g.drawImage(img, 0, 0, null);
}
public LoadImageApp() {
try {
img = ImageIO.read(new File("127.0.0.1.jpg"));
} catch (IOException e) {
}
}
public Dimension getPreferredSize() {
if (img == null) {
return new Dimension(100,100);
} else {
return new Dimension(img.getWidth(null), img.getHeight(null));
}
}
public static void main(String[] args) {
JFrame f = new JFrame("Load Image Sample");
JPanel jp=new JPanel();
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
//f.add(new LoadImageApp());
//jp.setOpaque(false);
f.setContentPane(jp);
jp.add(new LoadImageApp());
f.pack();
f.setVisible(true);
}
}