0

「以下は同等です」というセクションに到達すると、vc.setFullScreenWindow(window)1つのコマンドですべてを実行する方法を示そうとしていますが、これにはかなり慣れていないため、混乱しています。

それが私の主な質問ですが、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 に答える