title: Java - paintComponent won't show drawings on JPanel
body: <p>I've gotten stuck trying to draw on a <code>JPanel</code>. I've learned how to create a <code>JFrame</code>, a <code>JPanel</code>, add event handlers, do the same in applets, and some other basic GUI development. But everytime I try to draw on a <code>JPanel</code> using the <code>paintComponent(Graphics g)</code> or <code>paint(Graphics g)</code> methods, nothing shows up. Buttons, as well as other <code>JComponents</code>, show up just fine. But <code>g.drawString</code>, <code>g.drawRect</code>, etc result in a blank <code>JFrame</code> window.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>import java.awt.*;
  import javax.swing.*;
  import java.awt.event.*;
  import javax.swing.event.*;
  
  public class Game extends JPanel {
      public static void main(String[] args) {
          new Game().game();
      }
  
      JPanel panel;
      JButton button2;
      JButton button;
  
      public void game() {
          panel = new JPanel();
          button = new JButton("Ok");
          panel.setLayout(new FlowLayout());
          panel.add(button);
  
          button2 = new JButton("Cancel");
  
          JFrame frame = new JFrame("Game");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(500,500);
          frame.setResizable(false);
          frame.add(panel);
  
          frame.setVisible(true); 
      }
  
      public void paintComponent(Graphics g) {
          super.paintComponent(g);
          g.drawString("hi",100,100);
          g.fillRect(100,50,200,300)
      }
  }
  </code></pre>