制作一个全屏跳棋游戏,用于在 java 中学习/练习绘图/摇摆,但无法将其绘制在屏幕的上部(位置 [0,0] 大约在我的屏幕顶部下方 20 像素。)
这是示例代码(我现在只是使用 alt+F4 退出)
public class Game extends JFrame{
//get resolution
public static GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
public static final int mWidth = gd.getDisplayMode().getWidth();
public static final int mHeight = gd.getDisplayMode().getHeight();
public static void main(String[] a) {
//create game window
JFrame window = new JFrame();
Board board = new Board();
gd.setFullScreenWindow(window);
window.setSize(mWidth, mHeight);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setResizable(false);
window.setVisible(true);
window.add(board);
board.repaint();
}
}
public class Board extends JComponent{
public void paint(Graphics b){
b.fillRect(0, 0, Game.mWidth-7, Game.mHeight-29);
repaint();
}
}