Why the paint() method is called two times ?
This code calls two times the paint() method when I run this:
package KLL;
import javax.swing.*;
import java.awt.*;
public class KLL extends JFrame {
static int a;
static int b;
public KLL(){
super();
a=12;
b=20;
setSize(300,300);
setVisible(true);
}
public void paint(Graphics g){
System.out.println(a);
Graphics2D g2;
g2=(Graphics2D) g;
g2.draw3DRect(100, 100, a, b, false);
}
public static void main (String[] args) throws InterruptedException{
KLL K=new KLL();
Thread.currentThread();
Thread.sleep(3000);
a=80;
b=120;
K.repaint();
Thread.sleep(3000);
a=200;
b=120;
K.repaint();
}
}
When using repaint() it is called only 1 time which is understandable. But why when I run this code it is called two times at the beginning ??