How to make full screen java applets?

前端 未结 4 1504
情话喂你
情话喂你 2021-02-20 04:59

I am designing a psychology experiment with java applets. I have to make my java applets full screen. What is the best way of doing this and how can I do this.

Since I

相关标签:
4条回答
  • 2021-02-20 05:30

    I've found a solution for this problem that works fine. Tested in Linux 64 bits (Chrome and Firefox) and in Windows 7 64 bits (Chrome and Explorer)

    The only problem has been that my applet uses all the space in the browser and when the user switch off the full screen mode, the applet is not scaled to the browser size. The solution has been to keep the previous size of the applet before to enter in a fullscreen mode and then, set this size when the applet returns to the normal mode:

    public void setFullScreen() {   
            if (!this.fullscreen) {
                size = this.getSize();
                if (this.parent == null) {
                    this.parent = getParent();
                }
                this.frame = new Frame();
                this.frame.setUndecorated(true);
                this.frame.add(this);
                this.frame.setVisible(true);
    
                GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
                GraphicsDevice[] devices = ge.getScreenDevices();
                devices[0].setFullScreenWindow(this.frame);
                this.fullscreen = true;
            } else {
                if (this.parent != null) {
                    this.parent.add(this);
                }
                if (this.frame != null) {
                    this.frame.dispose();
                }
                this.fullscreen = false;
                this.setSize(size);
                this.revalidate();
            }       
            this.requestFocus();
        }
    
    0 讨论(0)
  • 2021-02-20 05:34

    Why not just open a new Frame from the applet (either from the "start()" method or, preferably, after the user presses an "open" button) and set it to be maximized?

    JFrame frame = new JFrame();
    //more initialization code here
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setSize(dim.width, dim.height);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    

    Don't forget: The JFrame should be created and opened from the EDT. Applet start() is not guaranteed to be called on that thread, so use SwingUtilities.invokeLater(). Of course, if you opt for the button route, button listener is called on the EDT, so you should be safe.

    0 讨论(0)
  • 2021-02-20 05:42

    I think you want to use WebStart. You can deploy from a browser but it is otherwise a full blown application. There are a few browserish security restrictions, but, as you're using an Applet currently, I think I can assume they're not a problem.

    0 讨论(0)
  • 2021-02-20 05:46

    The obvious answer is don't use applets. Write an application that uses a JFrame or JWindow as its top-level container. It's not a huge amount of work to convert an applet into an application. Applets are designed to be embedded in something else, usually a web page.

    If you already have an applet and want to make it full screen, there's two quick and dirty hacks:

    1). If you know the screen resolution, just set the applet parameters to be that size in the HTML and then run the browser in full screen mode.

    2). Run the applet in appletviewer, rather than a web page, and maximise the appletviewer window.

    0 讨论(0)
提交回复
热议问题