title: Drawing in Java using Canvas
body: <p>I want to draw in Java's Canvas but can't get it work because I don't know what I'm doing.  Here's my simple code:</p>
  
  <pre><code>import javax.swing.JFrame;
  import java.awt.Canvas;
  import java.awt.Graphics;
  import java.awt.Color;
  
  public class Program
  {
      public static void main(String[] args)
      {
          JFrame frmMain = new JFrame();
          frmMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frmMain.setSize(400, 400);
  
          Canvas cnvs = new Canvas();
          cnvs.setSize(400, 400);
  
          frmMain.add(cnvs);
          frmMain.setVisible(true);
  
          Graphics g = cnvs.getGraphics();
          g.setColor(new Color(255, 0, 0));
          g.drawString("Hello", 200, 200);
      }
  }
  </code></pre>
  
  <p>Nothing appears on the window.</p>
  
  <p>Am I wrong to think that Canvas is a paper and Graphics is my Pencil? Is that how it works?</p>