title: Drawing an object using getGraphics() without extending JFrame
body: <p>How can I draw an object without a class (which extends <code>JFrame</code>)? I found <code>getGraphics</code> method but it doesnt draw the object.</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  public class Main {
      public static void main(String[] args) {
          JFrame frame = new JFrame();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setVisible(true);
          frame.setSize(600, 400);
  
          JPanel panel = new JPanel();
          frame.add(panel);
  
          Graphics g = panel.getGraphics();
          g.setColor(Color.BLUE);
          g.fillRect(0, 0, 100, 100);
      }
  }
  </code></pre>