title: Why are Graphics2D rectangles not displayed?
body: <p>I need to be able to display filled rectangles for the program i am creating, however the following code produces the following GUI with only the black text 'test' after calling start then change, could anyone explayin why please?</p>
  
  <pre><code>package core;
  
  import java.awt.Color;
  import java.awt.Graphics2D;
  import javax.swing.JFrame;
  
  @SuppressWarnings("serial")
  public class GUI extends JFrame{
  
  private Graphics2D g;
  private int[][][] clickable;
  
  public void start(){
  
      this.setSize(500, 500);
      this.setTitle("Placeholder");
      this.setVisible(true);
      g = (Graphics2D) this.getGraphics();
  }       
  
  public void change(String[] fields, int type[], boolean forwards){
      g.setColor(new Color(28,35,57));
      g.drawRect(0, 0, 100, 100);
      g.drawRect(50, 50, 150, 150);
      g.fillRect(0, 0, 100, 100);
      g.drawString("test", 300, 300);     
  }
  }
  </code></pre>
  
  <p>And here is what it looks like ..</p>
  
  <p><a href="https://i.stack.imgur.com/9AGiv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9AGiv.png" alt="output"></a></p>