0

当我到达“以下是等效的”部分时,我试图展示如何执行vc.setFullScreenWindow(window)所有命令,但我自己很困惑,因为我对此很陌生。

这是我的主要问题,但如果有人能解释任何值得注意的关于 GraphicsEnvironment 或 JFrame 的内容,我将非常感激。

import java.awt.*;
import javax.swing.JFrame;

// Screens2 can use all methods that JFrame has
public class Screens2 extends JFrame{


// Video Card used for Utilizing the graphics on the computer SCREEN
private GraphicsDevice vc;

// The Constructor merely sets the default Screen graphics up
public Screens2(){

    // The OS specific Graphics Envirionment
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();


    // Graphics Device vc = The Default();
    vc = env.getDefaultScreenDevice();

}

// he DisplayMode class encapsulates the bit depth, 
// height, width, and refresh rate of a GraphicsDevice. 
// this method also takes in a JFrame to Display the DisplayMode
public void setFullScree(DisplayMode dm, JFrame window){

    // Nothing fancy
    window.setUndecorated(true);
    window.setResizable(false);

    // The following is equivalent =======================================================
    private GraphicsDevice.GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(window);
    vc.setFullScreenWindow(window);

}
}
4

1 回答 1

3

你提到的这条线有点混乱:

private GraphicsDevice.GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(window);

编译器假定您要在方法内创建私有成员变量。请参阅声明成员变量GraphicsDevice也不需要启动。

将其替换为以下内容:

GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(window);

查看课程:全屏独占模式 API,了解有关全屏独占模式的更多详细信息。

考虑以下示例,该示例演示了全屏模式下的帧:

import java.awt.BorderLayout;
import java.awt.GraphicsEnvironment;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;

public class FullScreenDemo {

    private static void createAndShowGUI() {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        frame.setLayout(new BorderLayout());
        frame.add(new JLabel("Hit Escape to exit full screen", JLabel.CENTER), BorderLayout.CENTER);

        frame.setSize(300, 300);

        KeyStroke escapeKeyStroke = KeyStroke.getKeyStroke("ESCAPE");
        Action escapeAction = new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(null);       
            }
        };

        frame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeKeyStroke, "ESCAPE");
        frame.getRootPane().getActionMap().put("ESCAPE", escapeAction);     

        GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(frame);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}
于 2012-07-23T04:49:14.150 回答