From e25cc615cdfdca78adebb8455e7ee10f15bf7948 Mon Sep 17 00:00:00 2001 From: ericnerdo Date: Mon, 9 May 2016 17:00:39 +0200 Subject: [PATCH] Display.java now extends JPanel. paintComponent() overridden. --- cicaprojekt/Display.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cicaprojekt/Display.java b/cicaprojekt/Display.java index b07c634..0a77bbc 100644 --- a/cicaprojekt/Display.java +++ b/cicaprojekt/Display.java @@ -1,14 +1,18 @@ package cicaprojekt; +import java.awt.Graphics; import java.io.IOException; import java.util.ArrayList; import java.util.List; -public class Display { +import javax.swing.JPanel; + +public class Display extends JPanel{ private List visuals; public Display() { visuals = new ArrayList<>(); + setVisible(false); } public void addVisual(Drawer visual) { @@ -18,5 +22,14 @@ public class Display { public void drawVisuals() throws IOException { for(Drawer visual : visuals) visual.draw(); + repaint(); + setVisible(true); } -} + + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + for(Drawer visual : visuals) + g.drawImage(visual.getImage(), visual.getTileX() * 64, visual.getTileY() * 64, null); + } +} \ No newline at end of file