gpt4 book ai didi

java - 在 Ubuntu 上将全屏设置为 java.awt.Window

转载 作者:行者123 更新时间:2023-12-01 12:39:04 25 4
gpt4 key购买 nike

我想将全屏设置为 java.awt.Window,但它在 Ubuntu 上不起作用。

以下代码不起作用:

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

public class test
{
public static void main(String[] args)
{
Window wnd = new Window(new Frame());

wnd.setLocation(100, 100);
wnd.setSize(wnd.getToolkit().getScreenSize());
wnd.setBackground(Color.red);
wnd.setVisible(true);
}
}

我认为,问题出在:

  wnd.setSize(wnd.getToolkit().getScreenSize());

如果我将其更改为:

  wnd.setSize(400,300)

它会起作用的。

有人可以帮助我吗?非常感谢!

最佳答案

您还可以使用类 Toolkit 来完成此操作(在 Win7 上):

//other imports
import java.awt.Toolkit;

public class test
{
public static void main(String[] args)
{
Window wnd = new Window(new Frame());

//Of course this set the window 100 px to the right
// and 100 to the bottom
wnd.setLocation(100, 100);

//You use the Toolkit class!!
//Now your window has the same size of your screen!!
wnd.setSize(Toolkit.getDefaultToolkit().getScreenSize());

wnd.setBackground(Color.red);
wnd.setVisible(true);
}
}

有关 Toolkit 类的更多信息,请参阅文档链接:http://docs.oracle.com/javase/7/docs/api/java/awt/Toolkit.html

如果您使用的是 Ubuntu 或其他 Linux 版本,则使用“正常”方法将窗口或框架设置为全屏可能会遇到一些问题。有关更多信息,请参阅此帖子:Java Fullscreen mode not working on Ubuntu

关于java - 在 Ubuntu 上将全屏设置为 java.awt.Window,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25290482/

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