-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathLesson8.java
More file actions
41 lines (31 loc) · 963 Bytes
/
Copy pathLesson8.java
File metadata and controls
41 lines (31 loc) · 963 Bytes
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
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
class ImagePanel extends JPanel{
private Image img;
public ImagePanel(Image img){
this.img = img;
setSize(new Dimension(img.getWidth(null),img.getHeight(null)));
setPreferredSize(new Dimension(img.getWidth(null),img.getHeight(null)));
setLayout(null);
}
public void paintComponent(Graphics g){
g.drawImage(img, 0, 0, null);
}
}
public class Lesson8 {
public static void main(String[] args) {
JFrame frame = new JFrame("Lesson 08");
frame.setSize(640, 480);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
ImagePanel panel = new ImagePanel(new ImageIcon("E:/Lessons/Java/Swing Lessons/image/image/bird.jpg").getImage());
frame.add(panel);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}