简体   繁体   English

如何使Java Applet自动全屏显示? (日食)

[英]How to make java applet auto fullscreen? (Eclipse)

Just wondering how I would make the java applet be fullscreen when I run it. 只是想知道我如何在运行Java小程序时使其全屏显示。 I don't want to manually do it with a setSize(); 我不想使用setSize();手动进行操作setSize(); command. 命令。 I was trying to get it so It would go fullscreen on any monitor regardless of the dimensions. 我试图获得它,因此无论尺寸如何,它都可以在任何显示器上全屏显示。 Was just curious if this was possible in eclipse and if so how would I go about doing it. 只是好奇是否可以在日食中使用,如果可以的话,我将如何去做。

I meant maximized, im on windows using Eclipse 我的意思是最大化使用Windows在Windows上使用Eclipse

Then simply use JFrame#setExtendedState and pass it JFame.MAXIMIZED_BOTH 然后只需使用JFrame#setExtendedState并将其传递给JFame.MAXIMIZED_BOTH

As an example... 举个例子...

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class Test {

    public static void main(String[] args) {
        new Test();
    }

    public Test() {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                    ex.printStackTrace();
                }

                JFrame frame = new JFrame("Testing");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.add(new JLabel("I'm a happy bunny"));
                // The following two lines just set up the
                // "default" size of the frame
                frame.pack();
                frame.setLocationRelativeTo(null);
                frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
                frame.setVisible(true);
            }
        });
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM