Hi , post simple code , i have put in PaintComponent() a System.out.println() to see if enter in the code when i call repaint() and the answer is no , so repaint don’t call PaintComponent() why??:
import javax.net.ssl.KeyManager;
import javax.swing.JFrame;
import java.awt.GridLayout;
public class Frame extends JFrame{
public Frame(){
GamePanel g = new GamePanel();
add(g);
setTitle("Frame");
setSize(200,200);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
Frame F= new Frame();
}
}
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
public class GamePanel extends JPanel implements Runnable{
public static Thread thread;
public GamePanel(){
setBackground(Color.WHITE);
thread=new Thread(this);
thread.start();
}
public void PaintComponent(Graphics g){
System.out.println("into");
g.setColor(new Color(100,100,100));
g.fillRect(0,0,100,100);
}
public void run(){
while(true){
repaint();
try{
thread.sleep(1000);
}catch(InterruptedException e){}
}
}
}