title: How to fill the whole window in awt
body: <p>I'm using java awt to render a simple rectangle. I also have a rectangle to be used as the background of the window. The thing is, even though the background rectangle is set to the window's width and height, it still doesn't fit the whole thing. I've tried to Google this, but found results irrelevant to my needs. What's causing this?</p>
  
  <pre><code>import java.awt.Canvas;
  import java.awt.Dimension;
  import java.awt.Graphics2D;
  import java.awt.event.MouseAdapter;
  import java.awt.image.BufferStrategy;
  import java.awt.Color;
  
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  
  
  public class Game implements Runnable{
  
     final int WIDTH = 640;
     final int HEIGHT = 480;
  
     JFrame frame;
     Canvas canvas;
     BufferStrategy bufferStrategy;
  
     boolean running = false;
  
     public Game(){
        frame = new JFrame("Prototyping");
  
        JPanel panel = (JPanel) frame.getContentPane();
        panel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
        panel.setLayout(null);
  
  
        canvas = new Canvas();
        canvas.setBounds(0, 0, WIDTH, HEIGHT);
        canvas.setIgnoreRepaint(true);
  
        panel.add(canvas);
  
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setResizable(false);
        frame.setVisible(true);
  
        canvas.createBufferStrategy(2); 
        bufferStrategy = canvas.getBufferStrategy();
  
        canvas.requestFocus();
     }
  
  
  
     public void run(){
  
        running = true;
        while(running)         
           render();
     }
  
     private void render() {
        Graphics2D g = (Graphics2D) bufferStrategy.getDrawGraphics();
        g.clearRect(0, 0, WIDTH, HEIGHT);
        render(g);
        g.dispose();
        bufferStrategy.show();
     }
  
     protected void update(){
  
     }
  
     protected void render(Graphics2D g){
        g.setColor(Color.GRAY);
        g.fillRect(0, 0, WIDTH, HEIGHT);
  
        g.setColor(Color.BLUE);
        g.fillRect(100, 0, 200, 200);
     }
  
     public static void main(String [] args){
        Game game = new Game();
        new Thread(game).start();
     }
  
  }
  </code></pre>