Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Applet : Switching FullScreen on/off  (Read 10280 times)
0 Members and 1 Guest are viewing this topic.
Offline DzzD
« Posted 2009-03-09 19:23:26 »

use F5 to toggle fullscreen on/off

http://demo.dzzd.net/HelloWorld/HelloWorld.htm

code to put in the Applet to switch full screen

EDIT :copy / paste the below code in your applet and call switchFullScreen from where you want in your applet to switch fullscreen

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
   Frame frame = new Frame(); 
   Container parent;
   boolean fullscreen=false;
   
   public void switchFullScreen()
   {
      System.out.println("SWITCH");
      if(!fullscreen)
      {
         if(this.parent==null)
            this.parent=getParent();
         
         
           frame.setUndecorated(true);
           frame.add(this);
           frame.setVisible(true);
           
   
         GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
          GraphicsDevice[] devices = ge.getScreenDevices();
          devices[0].setFullScreenWindow(frame);
          fullscreen=true;      
       }
       else
       {
          parent.add(this);
          frame.dispose();
          fullscreen=false;
       }
       this.requestFocus();
   }
   


Offline kevglass

JGO Kernel


Medals: 120
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #1 - Posted 2009-03-09 19:30:53 »

Doesn't go fullscreen here. Big window, fills the screen apart from the task bar is still visible.

Windows XP.

Kev

Offline DzzD
« Reply #2 - Posted 2009-03-09 19:35:43 »

Doesn't go fullscreen here. Big window, fills the screen apart from the task bar is still visible.

Windows XP.

Kev

yes in fact it is not true exclusive fullscreen, so if you have your taskbar option set as "keep taskbar over other window" it will stay visible, you should also see the java warning wich is a good thing

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Abuse

JGO Coder


Medals: 11


falling into the abyss of reality


« Reply #3 - Posted 2009-03-09 20:09:01 »

If you go fullscreen in the browser (F11), then 'full screen' in the Applet actually reduces visible screen area! (browser fullscreen mode goes over the top of the taskbar)

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 743
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #4 - Posted 2009-03-09 20:15:51 »

In Opera (on Vista x64) it only works 1 time...

F5 -> big window (not fullscreen though)
F5 -> applet with cube
F5 -> white applet
F5 -> applet with cube
F5 -> white applet
etc

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline DzzD
« Reply #5 - Posted 2009-03-09 20:16:41 »

If you go fullscreen in the browser (F11), then 'full screen' in the Applet actually reduces visible screen area! (browser fullscreen mode goes over the top of the taskbar)

probably office task bar will too, yup dont know if it is really a big problem ? I am more worry about the below bug Sad


doesn't work for me..  I get a big window, but it doesn't cover the entire screen. It's like it's been offset to the screen coordinates of the original applet.

OS / Java Version / browser ? it look like another plugin bug

Offline DzzD
« Reply #6 - Posted 2009-03-09 20:18:42 »

In Opera (on Vista x64) it only works 1 time...

F5 -> big window (not fullscreen though)
F5 -> applet with cube
F5 -> white applet
F5 -> applet with cube
F5 -> white applet
etc

peraps that is because vista is made to be used only once   Smiley ?

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 743
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #7 - Posted 2009-03-09 20:24:34 »

Good point.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 743
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #8 - Posted 2009-03-09 20:27:48 »

In MSIE7 (on Vista x64) it only works in ODD attempts...

F5 -> big window (not fullscreen though)
F5 -> applet with cube
F5 -> white applet
F5 -> applet with cube
F5 -> big window (not fullscreen though)
F5 -> applet with cube
F5 -> white applet
F5 -> applet with cube
F5 -> big window (not fullscreen though)
etc

 Grin

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline DzzD
« Reply #9 - Posted 2009-03-09 20:34:46 »

In MSIE7 (on Vista x64) it only works in ODD attempts...

F5 -> big window (not fullscreen though)
F5 -> applet with cube
F5 -> white applet
F5 -> applet with cube
F5 -> big window (not fullscreen though)
F5 -> applet with cube
F5 -> white applet
F5 -> applet with cube
F5 -> big window (not fullscreen though)
etc

 Grin
anyway it is pretty regular Smiley

maybe the refresh IE F5 key doesn't help, maybe switching by clicking on a nice fullscreen icon at the corner of the applet will work better (for focus).


Quote
big window (not fullscreen though)

how big ?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 743
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #10 - Posted 2009-03-09 20:43:44 »

Everything but the taskbar, so even the sidebar is obscured, normal maximized windows do not overlap the sidebar.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline bienator

Senior Member




OutOfCoffeeException


« Reply #11 - Posted 2009-03-09 21:10:36 »

works on ubuntu with 6u14b02. I am curious, why have you chosen the refresh button as fullscreen switch (to workaround a bug)? I have to refocus the applet each time after restoring from fullscreen to avoid page reloads.

Offline DzzD
« Reply #12 - Posted 2009-03-09 21:15:09 »

I did not really choose anything this was a popup code written today in around 5 minutes, there are still some bug but I am sure it can be usefull. just a sample that can be improved.

EDIT : to use it you only need to copy paste the above code into your applet and call switchFullScreen when you want to switch your appelt to fullscreen. like onkepress(){if... switchFullScreen )

Offline Ranger
« Reply #13 - Posted 2009-03-09 21:58:39 »

Cool!  Worked on Firefox + Chrome on Vista 32bit.  Had problems on MSIE, but I thinks that's because IE was intercepting the F5 key and trying to do a refresh.  Thanks for the code.  Smiley
Offline DzzD
« Reply #14 - Posted 2009-03-09 23:19:25 »

improved version :

some little improvment as applet autoresize : http://demo.dzzd.net/HelloWorld/HelloWorld.htm

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
   private Frame frame ; 
   private Container parent;
   private boolean fullscreen=false;

   /**
    * Toggle Applet to fullscreen.
    *
     * @param flag true to go into fullscreen or false to restore
     */
       
   public void setFullScreen(boolean flag)
   {
      if(flag && this.fullscreen)
         return;
         
      if(flag)
      {
         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.setBounds(0,0,this.getParent().getSize().width,this.getParent().getSize().height);
       
       
       this.requestFocus();
   }

Offline Ranger
« Reply #15 - Posted 2009-03-10 00:21:34 »

Not sure why, but in IE, the requestFocus doesn't seem to be working when exiting from full screen mode.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 743
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #16 - Posted 2009-03-10 00:32:14 »

Just replace F5 by SPACE, or anything else because every browser refreshes the page on F5, the moment the applet loses focus. It makes testing this code very unintuitive.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Ranger
« Reply #17 - Posted 2009-03-10 00:53:50 »

Just replace F5 by SPACE, or anything else because every browser refreshes the page on F5, the moment the applet loses focus. It makes testing this code very unintuitive.

True, however, the Applet shouldn't lose focus when switching between full screen (AKA "Maximised Window") and back, as if it does, you'll also get issues with F1, F11, Backspace, ...
Offline DzzD
« Reply #18 - Posted 2009-03-10 02:01:13 »

maybe the best would be an icon to click

Online princec

JGO Kernel


Medals: 342
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #19 - Posted 2009-03-10 12:21:43 »

Can't it post a request focus?

Cas Smiley

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 743
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #20 - Posted 2009-03-10 15:51:40 »

Can't it post a request focus?

Cas Smiley



1  
2  
3  
4  
5  
6  
               public void setFullScreen(boolean flag)
               {
                    // ... snip ...

                    this.requestFocus();
               }


 Wink

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline DzzD
« Reply #21 - Posted 2009-03-10 16:33:33 »


yes it already does, but for web security you cannot gain focus whenever you want within applet (same as in javascrit)

Offline bienator

Senior Member




OutOfCoffeeException


« Reply #22 - Posted 2009-03-10 17:32:23 »

there could be a race condition involved since it works "most of the time" without refreshing the page.

you could try to delay the focus request a bit by putting it to the end of the EDT queue.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
          if(this.parent!=null)
               this.parent.add(this);
          if(this.frame!=null)
             this.frame.dispose();
          this.fullscreen=false;
       }
       this.setBounds(0,0,this.getParent().getSize().width,this.getParent().getSize().height);
       
       SwingUtils.invokeLater(new Runnable() {
public void run() {this.requestFocus();}
});


FocusListener added to the applet's content pane with System.out.println() would help to debug further whether its a ignored requestFocus() issue or something else.

Offline DzzD
« Reply #23 - Posted 2009-06-30 06:03:03 »

I have made some few modification and find something strange, it seems that I success (bt that was not really my goal... and it look more like a hack than a success but...) to switch pseudo-fullscreen without anykind of Java Alert message(at least with Java 1.6-07)

anyone can try it and tell me if they can see the "Window Applet Alert Message" or like...

=> also this version work with applet 1.1 except that the title bar is not removed


http://demo.dzzd.net/HelloWorld/HelloWorld.htm

Offline zoto

Senior Member


Medals: 4



« Reply #24 - Posted 2009-06-30 11:53:52 »

It worked great here, firefox/vista32/Java1.6.13. I saw no security message and could toggle back and forth several times. The taskbar was not covered but the rest of the screen was.
Offline DzzD
« Reply #25 - Posted 2009-06-30 12:08:42 »

It worked great here, firefox/vista32/Java1.6.13. I saw no security message and could toggle back and forth several times. The taskbar was not covered but the rest of the screen was.
thanks zoto, but no security message is normal, I was more wondering about the "window alert" that may be show in the bottom of the screen or as an exclamation icon (something that warn you that this is a Java window), but it seems that I was wrong when saying it does not appear, it seems to only be the case when trying it locally over internet there is a little banner at the bottom of the fullscreen window containing the text "Java window".

do you have such icon exclamation or text banner when going into fullscreen ?


note that the first post source code is still the old one wich as a cupple of issue (as not working on older  JVM),  I will update with the new one ASAP

Offline jojoh

JGO Knight


Medals: 5
Projects: 7


games4j.com


« Reply #26 - Posted 2009-06-30 12:44:41 »

Worked mostly fine(or as you described Smiley ) here, and no "window alert" but task-bar visible.

WinXP, java 1.6.13. FF 3, IE 7

Aside:
IE 7 (F5) cycled applet - fullscreen - applet - reload - fullscreen - applet - reload
FF F5 worked as toggle.
OutOfMemError killed it after a while

Offline DzzD
« Reply #27 - Posted 2009-06-30 12:54:00 »

Worked mostly fine(or as you described Smiley ) here, and no "window alert" but task-bar visible.

WinXP, java 1.6.13. FF 3, IE 7

Aside:
IE 7 (F5) cycled applet - fullscreen - applet - reload - fullscreen - applet - reload
FF F5 worked as toggle.
OutOfMemError killed it after a while

about the reload as you can guess this is normal .... my stupidness... the key I have choosen to switch to fulscreen (F5) was not the best idea I could have...

Quote
FF .F5 worked as toggle
OutOfMemError killed it after a while
not sur I understand , sry ... what do you mean ? did you get OutOfMemory after one or more than one switch , or does it dont work on FF ?

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (22 views)
2014-07-24 01:59:36

Riven (20 views)
2014-07-23 21:16:32

Riven (17 views)
2014-07-23 21:07:15

Riven (20 views)
2014-07-23 20:56:16

ctomni231 (48 views)
2014-07-18 06:55:21

Zero Volt (44 views)
2014-07-17 23:47:54

danieldean (35 views)
2014-07-17 23:41:23

MustardPeter (38 views)
2014-07-16 23:30:00

Cero (53 views)
2014-07-16 00:42:17

Riven (52 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!