title: Canvas not drawing to JFrame
body: <p>I've been looking around for an answer to this, re-written my code multiple times, still nothing. Essentially I am trying to draw to a JFrame containing just a simple rectangle, yet each time nothing shows in the Frame - its just blank.</p>
  
  <pre><code>package com.Graphics;
  
  import java.awt.*;
  import java.awt.image.*;
  import javax.swing.*;
  
  public class GraphicsMain {
  
      public static void main(String[] args) {
  
          GraphicsMain myGraphics = new GraphicsMain();
  
          myGraphics.createDisplay();
  
      }
  
      void createDisplay(){
  
          int width = 500;
          int height = 500;
          String title = "TestFrame";
          Graphics g;
  
          Canvas myCanvas = new Canvas();
          JFrame myFrame = new JFrame(title);
  
          myFrame.setVisible(true);
          myFrame.setResizable(false);
          myFrame.setSize(width, height);
          myFrame.setLocationRelativeTo(null);
          myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
          myCanvas.setPreferredSize(new Dimension(500, 500));
          myCanvas.setMaximumSize(new Dimension(500, 500));
          myCanvas.setMinimumSize(new Dimension(500, 500));
  
          myFrame.add(myCanvas);
          myFrame.pack();
  
          myCanvas.createBufferStrategy(2);
  
          BufferStrategy bs = myCanvas.getBufferStrategy();
  
          g = bs.getDrawGraphics();
  
          g.setColor(Color.red);
          g.fillRect(10, 50, 50, 70);
  
          bs.show();
          g.dispose();
      }
  }
  </code></pre>
  
  <p>I realize conventions here are terrible - this is just a practice for me with graphics. Normally I would have this broken into separate classes etc. Any help is greatly appreciated. Thank you.</p>