I was thinking of a cool mechanic of a game that is played on your Desktop. I’d like to have the background of my JFrame be transparent so the JFrame would be fullscreen and it would look just like your Desktop. So, how would I do this? Is it even possible?
I’ve looked into something like this before. There’s a way to do it, but it’s very buggy and just not worth using at all.
Well thats a shame.
Google is your friend:
http://docs.oracle.com/javase/tutorial/uiswing/misc/trans_shaped_windows.html
:edit:
Looks like Oracle made a booboo; the jnlp link for the 3rd example (ShapedWindow) is wrong.
If the JFrame is fullscreen then you can take a screen capture with the java.awt.Robot class and draw that as the background of your JFrame. Unless the user has something that is animating on the desktop there won’t be any difference. You probably need to take a screen capture and analyze it anyway if you need the game to somehow interact with what the user has on the desktop.
Another interesting implementation would be to use small undecorated JFrames just bigger than your sprites and to move them around manually by changing the JFrames positions. This could allow the user to continue to interact with their desktop by moving icons around. Note that some window managers or settings of window manager will not respect your request to make a window undecorated. But I think it will work on the most common platforms.
JFrame.setUndecorated(true);
JFrame.setOpacity(0);
Not sure if those are the exact method names, but an undecorated transparent JFrame is probably what you want.