調用display()時打印出GamePanel's display! 但不顯示GamePanel's PrintComponent,也就是System.out.println("GamePanel's PrintComponent")這條語句沒有執行,repaint()方法為什麼不能調用方法 printComponent(Graphics g)
RepaintDemo
import java.awt.Graphics;
import javax.swing.JPanel;
public class RepaintDemo
{
public static void main(String args[])
{
GamePanel gamepanel = new GamePanel();
gamepanel.display();
}
}
class GamePanel extends JPanel
{
public void display()
{
System.out.println("GamePanel's display!");
this.repaint();
}
protected void printComponent(Graphics g) {
// TODO Auto-generated method stub
System.out.println("GamePanel's PrintComponent");
}
}