Skip to content

Commit

Permalink
rearrange to fix bug where things would initially spawn out of place
Browse files Browse the repository at this point in the history
  • Loading branch information
aspiringLich committed Apr 27, 2023
1 parent 72c7b40 commit a2c650f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/main/java/paintingcanvas/canvas/CanvasPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import javax.swing.*;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;

/**
Expand All @@ -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
Expand All @@ -48,7 +48,7 @@ public Dimension getPreferredSize() {
* @param g the <code>Graphics</code> context in which to paint
*/
public void paintComponent(Graphics g) {
var gc = (Graphics2D)g;
var gc = (Graphics2D) g;
synchronized (canvas.frameSync) {
canvas.frameSync.notify();
}
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit a2c650f

Please sign in to comment.