简体   繁体   English

全屏帧图像加载

[英]Full screen Frame image loading

I am trying to make a board game in Java using AWT. 我正在尝试使用AWT在Java中制作棋盘游戏。 I want to run this game in Full screen exclusive mode. 我想以全屏独家模式运行此游戏。 but the paint() method is not working. paint()方法不起作用。

Problem is i want to load and draw an image it on full screen frame, but the traditional paint() method won't allow me to do that. 问题是我想加载并在全屏帧上绘制图像,但传统的paint()方法不允许我这样做。

This example below will get you full-screen on your default screen device with an java.awt.Frame . 下面的示例将使用java.awt.Frame在您的默认屏幕设备全屏显示


public static void main(String[] args) throws IOException {

    Frame frame = new Frame("Test");
    frame.setUndecorated(true);

    frame.add(new Component() {
        BufferedImage img = ImageIO.read(new URL("http://upload.wikimedia.org/"+
                                                 "wikipedia/en/2/24/Lenna.png"));
        @Override
        public void paint(Graphics g) {
            super.paint(g);
            g.drawImage(img, 0, 0, getWidth(), getHeight(), this);
        }
    });

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gs = ge.getDefaultScreenDevice();
    gs.setFullScreenWindow(frame);
    frame.validate();
}

You can use the above example with swing aswell (just be sure to implement the paintComponent(Graphics g) method instead of paint ). 您可以将上面的示例与swing一起使用(只需确保实现paintComponent(Graphics g)方法而不是paint )。

 window.setExtendedState(Frame.MAXIMIZED_BOTH);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM