From 6a68387ed902620e4034f8bffa67fd2f940dbf44 Mon Sep 17 00:00:00 2001 From: jrtechs Date: Sat, 21 May 2016 16:42:23 -0400 Subject: [PATCH] creation of the drawable Element class --- src/tanks/DrawableElement.java | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/tanks/DrawableElement.java diff --git a/src/tanks/DrawableElement.java b/src/tanks/DrawableElement.java new file mode 100644 index 0000000..ddf1542 --- /dev/null +++ b/src/tanks/DrawableElement.java @@ -0,0 +1,43 @@ +/* +5-21-16 +jeffery R +super class for every object in DynamicBinding +allows for every object to have an image that can be drawn +every object will also have a (x,y) cordinate on the screen +*/ +package tanks; + +import java.awt.Graphics; +import java.awt.image.BufferedImage; +import java.io.IOException; +import javax.imageio.ImageIO; + + +public abstract class DrawableElement +{ + //fields + public String imageLocation; + public int x,y; + public BufferedImage img; + + //draws img onto the screen + public void Draw(Graphics g) + { + g.drawImage(img, x, y, null); + } + + //loads the image from the disk into the Buffered image img + public void LoadImage() + { + img = null; + try + { + img = ImageIO.read(getClass().getResourceAsStream(imageLocation)); + //img = ImageIO.read(new File(imageLoc)); + } + catch(IOException e) + { + System.out.println(e.toString()); + } + } +}