title: Why does JFrame paint graphics three times and not one?
body: <p>I made a simple program that paints a blue background and turns red after repainting 10 times and i noticed that whenever i run the program it paints the window three times at start and not one? Does anyone know why it does this?</p>
  
  <p>My MainClass:</p>
  
  <pre><code>package jframe_color;
  import javax.swing.*;
  import java.util.*;
  import java.awt.*;
  public class mainClass extends JFrame{
  
  public static void main(String[] args) {
  
      PaintWindow SetPaint = new PaintWindow()
  </code></pre>
  
  <p>And this is my PaintWindow class:</p>
  
  <pre><code>package jframe_color;
  import javax.swing.*;
  
  import java.util.*;
  import java.awt.*;
  public class PaintWindow extends JFrame {
  
  int count = 0;
  public PaintWindow(){
      setSize(400,400);
      setVisible(true);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
  
  public void paint(Graphics g){
      super.paint(g);
      if (count &lt; 10)
      {
          g.setColor(Color.BLUE);
          count += 1;
      }
      else
      {
          g.setColor(Color.RED);
      }
      g.fillRect(0,  0,  this.getWidth(), this.getHeight());
      g.setFont(new Font("Arial", Font.BOLD, 18));
      g.setColor(Color.BLACK);
      g.drawString("count is " + count, 100, 100);
  </code></pre>