How to make full screen java applets?

前端 未结 4 1480
情话喂你
情话喂你 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();
        }
    

提交回复
热议问题