title: draw rectangle in Jpanel
body: <p>I am trying to get my hands on GUI programming in java and wanted to draw a rectangle in Jpanel. Code does not give any error but I cannot get rectangle in the GUI. Can somebody please tell me what I am missing in the following code. I am sure it is pretty simple so please be gentle.</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  import javax.swing.*;
  public class HelloWorldGUI2 {
  
      private static class ButtonHandler implements ActionListener {
          public void actionPerformed(ActionEvent e) {
          System.exit(0);
          }
          }
      private static class RectDraw extends JPanel {
          public void paintComponent(Graphics g) {
          super.paintComponent(g);  
           g.drawRect(230,80,10,10);  
           g.setColor(Color.RED);  
           g.fillRect(230,80,10,10);  
          }
          }
      public static void main(String[] args) {
          JPanel content = new JPanel();
          RectDraw newrect= new RectDraw();
          JButton okButton= new JButton("OK");
          JButton clearButton= new JButton("Clear");
          ButtonHandler listener= new ButtonHandler();
          okButton.addActionListener(listener);
          clearButton.addActionListener(listener);
          content.add(okButton);
          content.add(clearButton);
          content.add(newrect);
          JFrame window = new JFrame("GUI Test");
          window.setContentPane(content);
          window.setSize(250,100);
          window.setLocation(100,100);
          window.setVisible(true);
          }
  
      }
  </code></pre>