Java 为什么不在全屏窗口的前20个像素上绘制呢?

Java 为什么不在全屏窗口的前20个像素上绘制呢?,java,fullscreen,paint,draw,screen-positioning,Java,Fullscreen,Paint,Draw,Screen Positioning,制作一个全屏跳棋游戏,用java学习/练习画图/挥杆,但无法在屏幕的上半部分画图。位置[0,0]比我的屏幕顶部低约20px 下面是我正在使用alt+F4退出的示例代码 您要做的是打电话: window.setUndecorated(true); 每一个框架可能有它的本地装饰,即框架和标题栏关闭,并设置未装饰。这只能在框架不可显示时进行 还需要进行更多的修改。从Board类中删除偏移值 public class Board extends JComponent{ public void

制作一个全屏跳棋游戏,用java学习/练习画图/挥杆,但无法在屏幕的上半部分画图。位置[0,0]比我的屏幕顶部低约20px

下面是我正在使用alt+F4退出的示例代码


您要做的是打电话:

window.setUndecorated(true);
每一个框架可能有它的本地装饰,即框架和标题栏关闭,并设置未装饰。这只能在框架不可显示时进行

还需要进行更多的修改。从Board类中删除偏移值

public class Board extends JComponent{
    public void paint(Graphics b){
        b.setColor(Color.BLUE); // Just to make the color more obvious
        b.fillRect(0, 0, Game.mWidth, Game.mHeight);
        repaint();
    }
}
并确保在添加和重新绘制电路板后调用window.setVisible,如下所示:

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();
        window.setUndecorated(true);
        Board board = new Board();

        gd.setFullScreenWindow(window);

        window.setSize(mWidth, mHeight);
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        window.setResizable(false);
        window.add(board);
        board.repaint();

        window.setVisible(true); // This needs to be last
    }
}

任何应用程序,如互联网浏览器,都可以在显示器的前20个像素上绘图吗?当我转到全屏F11时,可以。我的显示器没有问题,如果这是你问的,当我称之为filledRect时,由于某种原因,它不再显示,所以我不确定它是否有效not@Orion还有一些事情是必要的。我会更新我的答案。
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();
        window.setUndecorated(true);
        Board board = new Board();

        gd.setFullScreenWindow(window);

        window.setSize(mWidth, mHeight);
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        window.setResizable(false);
        window.add(board);
        board.repaint();

        window.setVisible(true); // This needs to be last
    }
}