给定以下代码:
class Game() {
private Shell shell;
public Game(Display display,int level)
{
shell.addPaintListener(new ExmaplePaintListener());
shell.setText("Basic shapes");
shell.setSize(900,900);
shell.setLocation(45, 45);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
}
听众:
private class ExmaplePaintListener implements PaintListener {
public void paintControl(PaintEvent e) {
drawMaze(e);
placeTreasuresInMaze2(e);
e.gc.dispose();
}
}
以及绘制迷宫的方法
private void drawMaze(PaintEvent e) {
// this method creates a new maze and draw it using GUI Java
}
我的问题是迷宫的窗口创建后,如果我用鼠标改变窗口的尺寸,那么该方法drawMaze
会在当前窗口中创建一个新的迷宫。这显然是一个错误,那么我的错误在哪里?也许与Constructor
班级有关Game
?
问候罗恩