gpt4 book ai didi

Java图形环境

转载 作者:行者123 更新时间:2023-12-02 00:17:44 25 4
gpt4 key购买 nike

当我到达“以下内容等效”部分时,我试图展示如何执行 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);

}
}

最佳答案

你提到的这一行有点困惑:

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

编译器假设您要在方法内创建私有(private)成员变量。请参阅Declaring Member Variables 。也不需要启动 GraphicsDevice

将其替换为以下内容:

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

查看Lesson: Full-Screen Exclusive Mode 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();
}
});
}
}

关于Java图形环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11605894/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com