diff --git a/src/main/java/paintingcanvas/canvas/CanvasPanel.java b/src/main/java/paintingcanvas/canvas/CanvasPanel.java index 666e30f..456a516 100644 --- a/src/main/java/paintingcanvas/canvas/CanvasPanel.java +++ b/src/main/java/paintingcanvas/canvas/CanvasPanel.java @@ -4,7 +4,6 @@ import javax.swing.*; import java.awt.*; -import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; /** @@ -22,19 +21,20 @@ public class CanvasPanel extends JPanel { public Canvas canvas; CanvasPanel(Canvas canvas, int width, int height, String title) { + this.initialWidth = width; + this.initialHeight = height; + this.canvas = canvas; jframe = new JFrame(); - this.initialWidth = width; - this.initialHeight = height; - jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jframe.setTitle(title); - jframe.setVisible(true); // jframe.setLayout(null); jframe.add(this); jframe.pack(); jframe.setLocationRelativeTo(null); + jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jframe.addComponentListener(new RenderLifecycle.ResizeListener(this)); + jframe.setVisible(true); } @Override @@ -48,7 +48,7 @@ public Dimension getPreferredSize() { * @param g the Graphics context in which to paint */ public void paintComponent(Graphics g) { - var gc = (Graphics2D)g; + var gc = (Graphics2D) g; synchronized (canvas.frameSync) { canvas.frameSync.notify(); } @@ -80,7 +80,7 @@ public void paintComponent(Graphics g) { // Render elements onto an image image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB); - var ig = (Graphics2D)image.getGraphics(); + var ig = (Graphics2D) image.getGraphics(); ig.setColor(Color.WHITE); ig.fillRect(0, 0, getWidth(), getHeight());