From 805d526fba446ac6215caa20fbd9ef71ed539436 Mon Sep 17 00:00:00 2001 From: Anton Johansson Date: Sun, 14 Dec 2008 18:35:21 +0100 Subject: [PATCH] Small rectangle moves --- build.xml | 2 +- src/se/umu/cs/dit06ajnajs/ATDView.java | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/build.xml b/build.xml index b7bb5c2..e5d46b8 100644 --- a/build.xml +++ b/build.xml @@ -93,7 +93,7 @@ - + diff --git a/src/se/umu/cs/dit06ajnajs/ATDView.java b/src/se/umu/cs/dit06ajnajs/ATDView.java index f972d59..b90984a 100644 --- a/src/se/umu/cs/dit06ajnajs/ATDView.java +++ b/src/se/umu/cs/dit06ajnajs/ATDView.java @@ -8,13 +8,15 @@ import java.awt.image.BufferedImage; import java.awt.Graphics; import java.awt.Color; import java.awt.Graphics2D; +import java.awt.AlphaComposite; +import java.awt.geom.Rectangle2D; public class ATDView { private ATDModel model; private JFrame frame; private Dimension frameDimension = new Dimension(200, 200); private JComponent gameComponent; - private Graphics gameGraphics; + private Graphics2D gameGraphics; public ATDView(ATDModel model) { this.model = model; @@ -44,7 +46,7 @@ public class ATDView { private class GameComponent extends JComponent { private Image backgroundImage; - private Image gameImage; + private BufferedImage gameImage; private int width; private int height; @@ -58,22 +60,28 @@ public class ATDView { this.backgroundImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics g = backgroundImage.getGraphics(); - g.setColor(Color.WHITE); - g.fillRect(0, 0, (int) dim.getWidth(), (int) dim.getHeight()); + g.setColor(Color.YELLOW); + g.fillRect(0, 0, width, height); // Game Image - this.gameImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); - ATDView.this.gameGraphics = gameImage.getGraphics(); + this.gameImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); + ATDView.this.gameGraphics = gameImage.createGraphics(); } @Override public void paintComponent(Graphics g) { System.out.println("paintComponent(...)"); - // Clear screen + g.drawImage(backgroundImage, 0, 0, null); // Should contain updated information from Controller g.drawImage(gameImage, 0, 0, null); + + // Clear Game Image image + Color transparent = new Color(0, 0, 0, 0); + gameGraphics.setColor(transparent); + gameGraphics.setComposite(AlphaComposite.Src); + gameGraphics.fill(new Rectangle2D.Double(0, 0, width, height)); } } } -- 2.11.4.GIT