我已经编写了一个 Sokoban 克隆作为我的学习计划的项目。自从升级到 JDK 7 后,我遇到了以下问题:当我JPanel
第一次调用我的 repaint() 方法时,我的 JPanel 右侧出现一个“阴影图像”,如下所示:之前:
之后:
我不知道是什么原因造成的,所以不太清楚要添加哪个代码。这是paint()方法:
public void paint(Graphics g) {
int x;
int y;
// draw column
for (int k = 0; k < field.getField().length; k++) {
y = (tileWidth * k); // Get y coordinate
// draw line
for (int l = 0; l < field.getField()[0].length; l++) {
FieldObj now = field.getField()[k][l];
x = (tileWidth * l); // Get x coordinate
// Wall
if (now instanceof Wall)
g.drawImage(Wall, x, y, tileWidth, tileWidth, null);
// Box
else if (now instanceof Box && ((Box) now).getStandingOnGoal())
g.drawImage(BoxOnG, x, y, tileWidth, tileWidth, null);
else if (now instanceof Box)
g.drawImage(Box, x, y, tileWidth, tileWidth, null);
// Man on Goal
else if (now instanceof Man
&& field.getMan().getStandingOnGoal()
&& field.getMan().getOr() == 0)
g.drawImage(ManGU, x, y, tileWidth, tileWidth, null);
else if (now instanceof Man
&& field.getMan().getStandingOnGoal()
&& field.getMan().getOr() == 1)
g.drawImage(ManGL, x, y, tileWidth, tileWidth, null);
else if (now instanceof Man
&& field.getMan().getStandingOnGoal()
&& field.getMan().getOr() == 2)
g.drawImage(ManGR, x, y, tileWidth, tileWidth, null);
else if (now instanceof Man
&& field.getMan().getStandingOnGoal()
&& field.getMan().getOr() == 3)
g.drawImage(ManGD, x, y, tileWidth, tileWidth, null);
// Man
else if (now instanceof Man && field.getMan().getOr() == 0)
g.drawImage(ManU, x, y, tileWidth, tileWidth, null);
else if (now instanceof Man && field.getMan().getOr() == 1)
g.drawImage(ManL, x, y, tileWidth, tileWidth, null);
else if (now instanceof Man && field.getMan().getOr() == 2)
g.drawImage(ManR, x, y, tileWidth, tileWidth, null);
else if (now instanceof Man && field.getMan().getOr() == 3)
g.drawImage(ManD, x, y, tileWidth, tileWidth, null);
// Floor
else if (now instanceof Floor && ((Floor) now).getGoal())
g.drawImage(Goal, x, y, tileWidth, tileWidth, null);
else
g.drawImage(Floor, x, y, tileWidth, tileWidth, null);
}
}
}
有什么建议么?你想看的其他代码?我会很感激任何帮助。一个