title: Java Paint Method Flashes and Disappears
body: <p>Hi I've been trying to mess around with Java GUI by altering a program I made that drew the mandelbrot set, but when I put if statements in the paint method it makes the image flash on the screen and then erase to a black screen.</p>
  
  <p>This is my paint method:</p>
  
  <pre><code>public void paintComponent(Graphics g)
  {
      if (clicked == false &amp;&amp; count == 0)
      {
  
          drawMandelbrot(g); //sends graphics object to the method that draws the Mandelbrot set
          clicked = !clicked;
      }
  
      zoom(g);
      repaint();
  
  }
  
  public void zoom(Graphics g)
  {
  
      if (count &gt; 0 &amp;&amp; clicked == false)
      {
          g.setColor(Color.white);
          g.fillRect(0,0, 400, 400);
  
          clicked = !clicked;
      }
  }
  </code></pre>
  
  <p>I know that there is noting wrong with the drawMandelbrot() function because it's worked before, and I know that it should not be the zoom() function because count is only increased at mousePressed.</p>
  
  <p>Any ideas?! I've tried commenting so many parts out and sometimes it stays on the screen, but I run it again and it doesn't. Is Swing/AWT this wonky?</p>
  
  <p>UPDATE:</p>
  
  <p>I figured out that the problem had to do with setting the background colour. I set the background colour of the frame in the main function, but for some reason (still unknown to me) after painting the image, it set the background colour over it again.</p>
  
  <pre><code>public Mandelbrot (int w, int h) //constructor method that is only utilized to bring in the size of the screen
  {
      this.setBackground(Color.BLACK);
      addMouseListener(this);
      clicked = false;
      count = 0;
  }
  
  public void paintComponent(Graphics g)
  {
      super.paintComponent(g);
      if (clicked == false &amp;&amp; count == 0)
      {
  
          drawMandelbrot(g); //sends graphics object to the method that draws the Mandelbrot set
          clicked = !clicked;
      }
  
      zoom(g);
  
  }
  
  public void zoom(Graphics g)
  {
  
      if (count &gt; 0 &amp;&amp; clicked == false)
      {
      }
  }
  public void mouseReleased(MouseEvent e) 
  {
          zoomX = e.getX();
          count ++;
          clicked = !clicked;
          repaint();
          System.out.print(clicked);
  }
  </code></pre>
  
  <p>UPDATE 2:
  It still does not work, it worked for the first time but I tried running it again and the same thing as before occurred, and it ended with a black frame.</p>