import javax.swing.*;
import java.awt.*;public class TetrisGame extends JFrame {
private final int BOARD_WIDTH = 10;
private final int BOARD_HEIGHT = 20;public TetrisGame() {
setTitle("俄罗斯方块");
setSize(400, 800);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setResizable(false);Board board = new Board(BOARD_WIDTH, BOARD_HEIGHT);
add(board);setVisible(true);
}public static void main(String[] args) {
new TetrisGame();
}
}class Board extends JPanel {
private int boardWidth;
private int boardHeight;public Board(int width, int height) {
boardWidth = width;
boardHeight = height;
}public void paint(Graphics g) {
super.paint(g);for (int row = 0; row < boardHeight; row++) {
for (int col = 0; col < boardWidth; col++) {
int x = col * 30;
int y = row * 30;
g.drawRect(x, y, 30, 30);
}
}
}
}
45万+

被折叠的 条评论
为什么被折叠?



