2

super.paintComponent(g) 在这个示例代码中的作用是什么?

protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.setColor(Color.GRAY);
    g.fillRect(gridX * 50, gridY * 50, 50, 50);
    for (int i = 0;i < 10; i++) {
        for (int j = 0;j < 10; j++) {
            if (savedTiles[i][j])
                g.fillRect(i * 50, j * 50, 50, 50);
        }
    }
}
4

2 回答 2

4

超级教程http://download.oracle.com/javase/tutorial/java/IandI/super.html

于 2011-06-03T22:07:06.183 回答
0

这取决于您paintComponent从哪个超类覆盖 - 方法。但作为答案,它的目的是在运行覆盖之前调用同一方法的超类版本。

于 2011-06-03T22:03:04.427 回答