From d513d5f9fa6f0c9ca4ba0fb9cbf4bfe687070feb Mon Sep 17 00:00:00 2001 From: ericnerdo Date: Mon, 9 May 2016 16:52:04 +0200 Subject: [PATCH] Drawer.getImage() added. AbstractDrawer.java added to contain image for XXXDrawers. ImagePanel.java removed. --- .../{ImagePanel.java => AbstractDrawer.java} | 20 ++++++++----------- cicaprojekt/Drawer.java | 2 ++ cicaprojekt/FieldDrawer.java | 9 +++------ cicaprojekt/GapDrawer.java | 6 ++---- cicaprojekt/GateDrawer.java | 8 ++------ cicaprojekt/PlayerBaseDrawer.java | 7 ++----- cicaprojekt/PlayerDrawer.java | 7 ++----- cicaprojekt/ScaleDrawer.java | 8 ++------ cicaprojekt/WallDrawer.java | 8 ++------ 9 files changed, 25 insertions(+), 50 deletions(-) rename cicaprojekt/{ImagePanel.java => AbstractDrawer.java} (50%) diff --git a/cicaprojekt/ImagePanel.java b/cicaprojekt/AbstractDrawer.java similarity index 50% rename from cicaprojekt/ImagePanel.java rename to cicaprojekt/AbstractDrawer.java index 243a779..40c13ac 100644 --- a/cicaprojekt/ImagePanel.java +++ b/cicaprojekt/AbstractDrawer.java @@ -1,29 +1,25 @@ package cicaprojekt; -import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; -import javax.swing.JPanel; - -public class ImagePanel extends JPanel{ +public abstract class AbstractDrawer implements Drawer { private BufferedImage image; - public ImagePanel(String path) throws IOException { + public AbstractDrawer(String path) throws IOException { image = ImageIO.read(new File(path)); } - - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - g.drawImage(image, 0, 0, null); // see javadoc for more info on the parameters - } public void changeImage(String path) throws IOException { image = ImageIO.read(new File(path)); - repaint(); } + + @Override + public BufferedImage getImage() { + return image; + } + } \ No newline at end of file diff --git a/cicaprojekt/Drawer.java b/cicaprojekt/Drawer.java index 950e989..0b2638e 100644 --- a/cicaprojekt/Drawer.java +++ b/cicaprojekt/Drawer.java @@ -1,5 +1,6 @@ package cicaprojekt; +import java.awt.image.BufferedImage; import java.io.IOException; public interface Drawer { @@ -7,4 +8,5 @@ public interface Drawer { public void draw() throws IOException; public int getTileX(); public int getTileY(); + public BufferedImage getImage(); } diff --git a/cicaprojekt/FieldDrawer.java b/cicaprojekt/FieldDrawer.java index c00b26e..f4fb703 100644 --- a/cicaprojekt/FieldDrawer.java +++ b/cicaprojekt/FieldDrawer.java @@ -2,14 +2,12 @@ package cicaprojekt; import java.io.IOException; -public class FieldDrawer extends ImagePanel implements Drawer { - +public class FieldDrawer extends AbstractDrawer { Field field; public FieldDrawer(Field f) throws IOException { super("Field.png"); field = f; - setVisible(false); } @Override @@ -19,9 +17,7 @@ public class FieldDrawer extends ImagePanel implements Drawer { else if(field.hasZPM()) changeImage("ZPM.png"); else - changeImage("Field.png"); - - setVisible(true); + changeImage("Field.png"); } @Override @@ -34,4 +30,5 @@ public class FieldDrawer extends ImagePanel implements Drawer { return field.getY(); } + } diff --git a/cicaprojekt/GapDrawer.java b/cicaprojekt/GapDrawer.java index 9676fd0..8698d6a 100644 --- a/cicaprojekt/GapDrawer.java +++ b/cicaprojekt/GapDrawer.java @@ -2,19 +2,17 @@ package cicaprojekt; import java.io.IOException; -public class GapDrawer extends ImagePanel implements Drawer{ - +public class GapDrawer extends AbstractDrawer { private Gap gap; public GapDrawer(Gap g) throws IOException { super("Gap.png"); gap = g; - setVisible(false); } @Override public void draw() { - setVisible(true); + //TODO ezzel csinálni kéne valamit. } @Override diff --git a/cicaprojekt/GateDrawer.java b/cicaprojekt/GateDrawer.java index cb45d0e..99390d1 100644 --- a/cicaprojekt/GateDrawer.java +++ b/cicaprojekt/GateDrawer.java @@ -2,14 +2,12 @@ package cicaprojekt; import java.io.IOException; -public class GateDrawer extends ImagePanel implements Drawer{ - +public class GateDrawer extends AbstractDrawer { Gate gate; public GateDrawer(Gate g) throws IOException { super("ClosedGate.png"); gate = g; - setVisible(false); } @Override @@ -17,9 +15,7 @@ public class GateDrawer extends ImagePanel implements Drawer{ if(gate.isOpen()) changeImage("Field.png"); //TODO picture for open gate. else - changeImage("ClosedGate.png"); - - setVisible(true); + changeImage("ClosedGate.png"); } @Override diff --git a/cicaprojekt/PlayerBaseDrawer.java b/cicaprojekt/PlayerBaseDrawer.java index 1db44c7..d438d60 100644 --- a/cicaprojekt/PlayerBaseDrawer.java +++ b/cicaprojekt/PlayerBaseDrawer.java @@ -2,13 +2,12 @@ package cicaprojekt; import java.io.IOException; -public class PlayerBaseDrawer extends ImagePanel implements Drawer { +public class PlayerBaseDrawer extends AbstractDrawer implements Drawer { PlayerBase playerbase; public PlayerBaseDrawer(PlayerBase pb) throws IOException { super("Replicator.png"); playerbase = pb; - setVisible(false); } @Override @@ -31,9 +30,7 @@ public class PlayerBaseDrawer extends ImagePanel implements Drawer { changeImage("Replicator_west.png"); break; } - } - - setVisible(true); + } } @Override diff --git a/cicaprojekt/PlayerDrawer.java b/cicaprojekt/PlayerDrawer.java index f5013e5..7b06140 100644 --- a/cicaprojekt/PlayerDrawer.java +++ b/cicaprojekt/PlayerDrawer.java @@ -2,13 +2,12 @@ package cicaprojekt; import java.io.IOException; -public class PlayerDrawer extends ImagePanel implements Drawer { +public class PlayerDrawer extends AbstractDrawer implements Drawer { Player player; public PlayerDrawer(Player p) throws IOException { super("ONeill.png"); player = p; - setVisible(false); } @Override @@ -49,9 +48,7 @@ public class PlayerDrawer extends ImagePanel implements Drawer { break; } break; - } - - setVisible(true); + } } @Override diff --git a/cicaprojekt/ScaleDrawer.java b/cicaprojekt/ScaleDrawer.java index a11edf1..5f9304a 100644 --- a/cicaprojekt/ScaleDrawer.java +++ b/cicaprojekt/ScaleDrawer.java @@ -2,14 +2,12 @@ package cicaprojekt; import java.io.IOException; -public class ScaleDrawer extends ImagePanel implements Drawer { - +public class ScaleDrawer extends AbstractDrawer implements Drawer { Scale scale; public ScaleDrawer(Scale s) throws IOException { super("Scale.png"); scale = s; - setVisible(false); } @Override @@ -17,9 +15,7 @@ public class ScaleDrawer extends ImagePanel implements Drawer { if(scale.hasBox()) changeImage("Box.png"); //TODO Picture for Scale with box. else - changeImage("Scale.png"); - - setVisible(true); + changeImage("Scale.png"); } @Override diff --git a/cicaprojekt/WallDrawer.java b/cicaprojekt/WallDrawer.java index cf4a8bd..9e70b9b 100644 --- a/cicaprojekt/WallDrawer.java +++ b/cicaprojekt/WallDrawer.java @@ -2,14 +2,12 @@ package cicaprojekt; import java.io.IOException; -public class WallDrawer extends ImagePanel implements Drawer { - +public class WallDrawer extends AbstractDrawer implements Drawer { Wall wall; public WallDrawer(Wall w) throws IOException { super("Wall.png"); wall = w; - setVisible(false); } @Override @@ -34,9 +32,7 @@ public class WallDrawer extends ImagePanel implements Drawer { changeImage("Wall.png"); break; } - } - - setVisible(true); + } } @Override