我画了一个棋盘,但我的窗口太大了。我不知道如何更改窗口的大小。我用 JFrame 尝试过,但会弹出第二个窗口。有人可以帮我吗?我必须在方法“drawSquare”中添加一些东西吗?
棋盘图:
public class Pattern {
// change color names
public static final String BLACK = "schwarz";
public static final String WHITE = "weiss";
public enum TYPE {
SQUARE, CIRCLE, TRIANLGE
};
private final static int SIZE = 30; // square size
public static void drawChessboard(int rows, int columns, TYPE type) {
String color1 = BLACK;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
color1 = (color1 == BLACK) ? WHITE : BLACK; // Switches from one to another color
switch (type) {
case SQUARE:
drawSquare(i * SIZE, j * SIZE, SIZE, color1);
break;
case CIRCLE:
drawCircle(i * SIZE, j * SIZE, SIZE, color1);
default:
System.out.println("falscher typ"); // else
break;
}
}
color1 = (color1 == BLACK) ? WHITE : BLACK;
}
}
public static void main(String[] args) {
// JFrame frame = new JFrame("Chessboard");
// frame.setSize(250, 250);
drawChessboard(8, 8, TYPE.SQUARE);
// frame.setVisible(true);
}
// DrawSquares
private static void drawSquare(int x, int y, int size, String color) {
Quadrat lego;
lego = new Quadrat();
lego.groesseAendern(size);
lego.horizontalBewegen(x);
lego.farbeAendern(color);
lego.vertikalBewegen(y);
lego.sichtbarMachen();
}
// DrawCircles
private static void drawCircle(int x, int y, int size, String color) {
Kreis lego;
lego = new Kreis();
lego.groesseAendern(size);
lego.horizontalBewegen(x);
lego.farbeAendern(color);
lego.vertikalBewegen(y);
lego.sichtbarMachen();
}