Applet : Switching FullScreen on/off

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


	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();
	}
	

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

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)

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

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

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

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

Good point.

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

;D

anyway it is pretty regular :slight_smile:

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)
[/quote]
how big ?

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

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.

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 )

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. :slight_smile:

improved version :

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


	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();
	}

Not sure why, but in IE, the requestFocus doesn’t seem to be working when exiting from full screen mode.

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, …

maybe the best would be an icon to click

Can’t it post a request focus?

Cas :slight_smile: