From 87e98e00e0ca5ac4229091aa9bb0e5c09093f50f Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Thu, 13 Dec 2012 22:14:24 -0800 Subject: Tetris project from TCSS305 class. Original project was in SVN on the school servers, so the versioning history is gone. --- src/tetris/gui/ImagePanel.java | 70 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/tetris/gui/ImagePanel.java (limited to 'src/tetris/gui/ImagePanel.java') diff --git a/src/tetris/gui/ImagePanel.java b/src/tetris/gui/ImagePanel.java new file mode 100644 index 0000000..d558788 --- /dev/null +++ b/src/tetris/gui/ImagePanel.java @@ -0,0 +1,70 @@ +/* + * Jesse Morgan + * + * 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 + * @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); + } +} \ No newline at end of file -- cgit v1.2.3