title: Drawing shapes in Java
body: <p>I want to have a method that will draw a rectangle, another one that will draw an oval, another for a line, image, etc.</p>
  
  <p>I have tried multiple techniques I found online, and none of them work. This is the only one that doesn't crash it, and the one I have right now:</p>
  
  <pre><code>    @Override
  public void paintComponent(Graphics g){
      super.paintComponents(g);
  }
  
  public void DrawRect(int x, int y, int width, int height, Color color){
      Graphics2D g2D = image.createGraphics();
      g2D.setColor(Color.RED);
      g2D.fillRect(x, y, width, height);
      //g2D.dispose();
      //g2D=null;
  }
  </code></pre>
  
  <p>But it doesn't really display anything.</p>