From 8cc0136ee94d65ed09b9d9003832bcf629d762db Mon Sep 17 00:00:00 2001 From: ericnerdo Date: Mon, 9 May 2016 16:40:18 +0200 Subject: [PATCH] Revert "Drawer.java refactored: It is now an abstract class instead of an" This reverts commit 80b844900cdff3e4e1c89a2a7fcda112e6aba1ef. --- cicaprojekt/Drawer.java | 25 ++++--------------------- cicaprojekt/FieldDrawer.java | 5 ++++- cicaprojekt/GapDrawer.java | 6 ++++-- cicaprojekt/GateDrawer.java | 8 ++++++-- cicaprojekt/ImagePanel.java | 29 +++++++++++++++++++++++++++++ cicaprojekt/PlayerBaseDrawer.java | 4 +++- cicaprojekt/PlayerDrawer.java | 7 +++++-- cicaprojekt/ScaleDrawer.java | 5 ++++- cicaprojekt/WallDrawer.java | 8 ++++++-- 9 files changed, 65 insertions(+), 32 deletions(-) create mode 100644 cicaprojekt/ImagePanel.java diff --git a/cicaprojekt/Drawer.java b/cicaprojekt/Drawer.java index abf86df..950e989 100644 --- a/cicaprojekt/Drawer.java +++ b/cicaprojekt/Drawer.java @@ -1,27 +1,10 @@ package cicaprojekt; -import java.awt.image.BufferedImage; -import java.io.File; import java.io.IOException; -import javax.imageio.ImageIO; - -public abstract class Drawer { - private BufferedImage image; - - public Drawer(String path) throws IOException { - image = ImageIO.read(new File(path)); - } - - public void changeImage(String path) throws IOException { - image = ImageIO.read(new File(path)); - } +public interface Drawer { - public BufferedImage getImage() { - return image; - } - - public abstract void draw() throws IOException; - public abstract int getTileX(); - public abstract int getTileY(); + public void draw() throws IOException; + public int getTileX(); + public int getTileY(); } diff --git a/cicaprojekt/FieldDrawer.java b/cicaprojekt/FieldDrawer.java index 1c63b8e..c00b26e 100644 --- a/cicaprojekt/FieldDrawer.java +++ b/cicaprojekt/FieldDrawer.java @@ -2,12 +2,14 @@ package cicaprojekt; import java.io.IOException; -public class FieldDrawer extends Drawer { +public class FieldDrawer extends ImagePanel implements Drawer { + Field field; public FieldDrawer(Field f) throws IOException { super("Field.png"); field = f; + setVisible(false); } @Override @@ -19,6 +21,7 @@ public class FieldDrawer extends Drawer { else changeImage("Field.png"); + setVisible(true); } @Override diff --git a/cicaprojekt/GapDrawer.java b/cicaprojekt/GapDrawer.java index aafbed5..9676fd0 100644 --- a/cicaprojekt/GapDrawer.java +++ b/cicaprojekt/GapDrawer.java @@ -2,17 +2,19 @@ package cicaprojekt; import java.io.IOException; -public class GapDrawer extends Drawer{ +public class GapDrawer extends ImagePanel implements Drawer{ + private Gap gap; public GapDrawer(Gap g) throws IOException { super("Gap.png"); gap = g; + setVisible(false); } @Override public void draw() { - //TODO kezdeni ezzel valamit. + setVisible(true); } @Override diff --git a/cicaprojekt/GateDrawer.java b/cicaprojekt/GateDrawer.java index 33ac692..cb45d0e 100644 --- a/cicaprojekt/GateDrawer.java +++ b/cicaprojekt/GateDrawer.java @@ -2,12 +2,14 @@ package cicaprojekt; import java.io.IOException; -public class GateDrawer extends Drawer{ +public class GateDrawer extends ImagePanel implements Drawer{ + Gate gate; public GateDrawer(Gate g) throws IOException { super("ClosedGate.png"); gate = g; + setVisible(false); } @Override @@ -15,7 +17,9 @@ public class GateDrawer extends Drawer{ if(gate.isOpen()) changeImage("Field.png"); //TODO picture for open gate. else - changeImage("ClosedGate.png"); + changeImage("ClosedGate.png"); + + setVisible(true); } @Override diff --git a/cicaprojekt/ImagePanel.java b/cicaprojekt/ImagePanel.java new file mode 100644 index 0000000..243a779 --- /dev/null +++ b/cicaprojekt/ImagePanel.java @@ -0,0 +1,29 @@ +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{ + + private BufferedImage image; + + public ImagePanel(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(); + } +} \ No newline at end of file diff --git a/cicaprojekt/PlayerBaseDrawer.java b/cicaprojekt/PlayerBaseDrawer.java index 7dc71f1..1db44c7 100644 --- a/cicaprojekt/PlayerBaseDrawer.java +++ b/cicaprojekt/PlayerBaseDrawer.java @@ -2,12 +2,13 @@ package cicaprojekt; import java.io.IOException; -public class PlayerBaseDrawer extends Drawer { +public class PlayerBaseDrawer extends ImagePanel implements Drawer { PlayerBase playerbase; public PlayerBaseDrawer(PlayerBase pb) throws IOException { super("Replicator.png"); playerbase = pb; + setVisible(false); } @Override @@ -32,6 +33,7 @@ public class PlayerBaseDrawer extends Drawer { } } + setVisible(true); } @Override diff --git a/cicaprojekt/PlayerDrawer.java b/cicaprojekt/PlayerDrawer.java index 69ee47f..f5013e5 100644 --- a/cicaprojekt/PlayerDrawer.java +++ b/cicaprojekt/PlayerDrawer.java @@ -2,12 +2,13 @@ package cicaprojekt; import java.io.IOException; -public class PlayerDrawer extends Drawer { +public class PlayerDrawer extends ImagePanel implements Drawer { Player player; public PlayerDrawer(Player p) throws IOException { super("ONeill.png"); player = p; + setVisible(false); } @Override @@ -48,7 +49,9 @@ public class PlayerDrawer extends Drawer { break; } break; - } + } + + setVisible(true); } @Override diff --git a/cicaprojekt/ScaleDrawer.java b/cicaprojekt/ScaleDrawer.java index 826898a..a11edf1 100644 --- a/cicaprojekt/ScaleDrawer.java +++ b/cicaprojekt/ScaleDrawer.java @@ -2,12 +2,14 @@ package cicaprojekt; import java.io.IOException; -public class ScaleDrawer extends Drawer { +public class ScaleDrawer extends ImagePanel implements Drawer { + Scale scale; public ScaleDrawer(Scale s) throws IOException { super("Scale.png"); scale = s; + setVisible(false); } @Override @@ -17,6 +19,7 @@ public class ScaleDrawer extends Drawer { else changeImage("Scale.png"); + setVisible(true); } @Override diff --git a/cicaprojekt/WallDrawer.java b/cicaprojekt/WallDrawer.java index 2447ad5..cf4a8bd 100644 --- a/cicaprojekt/WallDrawer.java +++ b/cicaprojekt/WallDrawer.java @@ -2,12 +2,14 @@ package cicaprojekt; import java.io.IOException; -public class WallDrawer extends Drawer { +public class WallDrawer extends ImagePanel implements Drawer { + Wall wall; public WallDrawer(Wall w) throws IOException { super("Wall.png"); wall = w; + setVisible(false); } @Override @@ -32,7 +34,9 @@ public class WallDrawer extends Drawer { changeImage("Wall.png"); break; } - } + } + + setVisible(true); } @Override