title: Java Window - Resizing
body: <p>I am coding a 2D Game and was wondering how to have that when someone resizes the window it will resize everything to make it the same (in comparison to the current window size). For example, I have a default 'TILEWIDTH', how could I make it that if someone resized the window to make it bigger it would also make the 'TILEWIDTH' bigger? At the moment in my launcher class (which has the Main method) it just creates a new display with a certain pixels width and height (If you resize the window it just creates a flashing black/grey area around the game display).</p>
  
  <p>This is my Display class (I create a new display in the launcher class in the main method):</p>
  
  <pre><code>package me.chickenpillow.game.display;
  
  import java.awt.Canvas;
  import java.awt.Dimension;
  
  import javax.swing.JFrame;
  
  public class Display {
  
  private JFrame frame;
  private Canvas canvas;
  
  private String title;
  private int width, height;
  
  public Display(String title, int width, int height) {
      this.title = title;
      this.width = width;
      this.height = height;
  
      createDisplay();
  }
  
  private void createDisplay() {
      frame = new JFrame(title);
      frame.setSize(width, height);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setResizable(true);
      frame.setLocationRelativeTo(null);
      frame.setVisible(true);
  
      canvas = new Canvas();
      canvas.setPreferredSize(new Dimension(width, height));
      canvas.setMaximumSize(new Dimension(width, height));
      canvas.setMinimumSize(new Dimension(width, height));
      canvas.setFocusable(false);
  
      frame.add(canvas);
      frame.pack();
  }
  
  public Canvas getCanvas() {
      return canvas;
  }
  
  public JFrame getFrame() {
      return frame;
  }
  </code></pre>
  
  <p>}</p>