blob: 1a2afd88aacbd80524ca5167f1801c6a537f3f5d (
plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
|
/*
* Jesse Morgan <jesterpm@u.washington.edu>
*
* TCSS 305 - Autumn 2009
* Tetris Project
* 17 November 2009
*/
package tetris.gui;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.JPanel;
/**
* Custom panel that displays an image in the background.
* @author Jesse Morgan <jesterpm@u.washington.edu>
* @version 1.0 4 Dec 2009
*/
@SuppressWarnings("serial")
public class ImagePanel extends JPanel {
/**
* The image that contains the background.
*/
private Image my_image;
/**
* Constructor. Defaults to BorderLayout.
* @param the_image The background Image.
*/
public ImagePanel(final Image the_image) {
super();
setLayout(new BorderLayout());
my_image = the_image;
setPreferredSize(new Dimension(the_image.getWidth(null), the_image.getHeight(null)));
}
/**
* @return the current background Image.
*/
public Image getBackgroundImage() {
return my_image;
}
/**
* Set a new background Image.
*
* @param the_image the new Image.
*/
public void setBackgroundImage(final Image the_image) {
my_image = the_image;
setPreferredSize(new Dimension(the_image.getWidth(null), the_image.getHeight(null)));
}
/**
* Draws the background image.
*
* @param the_graphics The Graphics Context.
*/
public void paintComponent(final Graphics the_graphics) {
setOpaque(false);
the_graphics.drawImage(my_image, 0, 0, null);
super.paintComponent(the_graphics);
}
}
|