[英]Setting the full screen to a java.awt.Window on Ubuntu
I want to set the full screen to a java.awt.Window, but it doesn't work on Ubuntu. 我想将全屏设置为java.awt.Window,但在Ubuntu上不起作用。
The following code doesn't work: 以下代码不起作用:
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);
}
}
I think, the problem is in the line: 我认为问题在于:
wnd.setSize(wnd.getToolkit().getScreenSize());
If I change it to: 如果我将其更改为:
wnd.setSize(400,300)
it will work. 它会工作。
Can someone help me? 有人能帮我吗? Thanks very much! 非常感谢!
You can also do it using the class Toolkit (on Win7): 您也可以使用类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);
}
}
For more information about the class Toolkit, see this link to the documentation: http://docs.oracle.com/javase/7/docs/api/java/awt/Toolkit.html 有关类Toolkit的更多信息,请参见以下文档链接: http : //docs.oracle.com/javase/7/docs/api/java/awt/Toolkit.html
If you are using Ubuntu or other linux versions, you could have some problems setting the full screen to your window or frame with the "normal" ways to do it. 如果您使用的是Ubuntu或其他Linux版本,则可能会遇到一些“常规”方式将全屏设置为窗口或框架的问题。 See this post for more information: Java Fullscreen mode not working on Ubuntu 有关更多信息,请参见此帖子: Java全屏模式在Ubuntu上不起作用
By using wnd.setLocation(100, 100)
you are placing the Full Screen size image at an 100pixel x and y offset from the top left corner of the screen. 通过使用wnd.setLocation(100, 100)
您将全屏尺寸图像放置在距屏幕wnd.setLocation(100, 100)
像素x和y偏移处。 Remove this and it will work 删除它,它将起作用
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);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.