views:

3583

answers:

5

Hello to all,

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 haven't been using java applets for 3 years(The last time I've used it was for a course homework :) ) I have forgotten most of the concepts. I googled and found that link: Dani web

But in the method described in above link you have to put a JFrame inside the applet which I have no idea how to do it.

Whatever I need a quick and dirty method b'cause I don't have much time and this is the reason why I asked it here.

Thanx in advance

+5  A: 

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.

Dan Dyer
yeah i think i read somewhere that applets are discouraged, and java web start should be used.
Johannes Schaub - litb
+3  A: 

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.

sblundy
A: 

Thanks Dan and the all the others that answered, the reason that I wanted to use applets that I will run the app from the browser. I am also concious about other options that, I can use processing and Javafx too. But I wanted to use the least painful method. The techniques that Dan suggested seemed like will work to me.

But there are some points that I haven't get let's say I have took the screen size with javascript screen.width and screen.height functions; but because applet is shown on the web browser that won't work since the browser is not fullscreen. I can make a full screen popup and put the applet inside that popup; but because in most of the browsers today popups are blocked or people blocks popups by 3rd party softw. this does not seemed reliable for me.

And the problem about the appletviewer how can i run the applet from the browser within appletviewer.

Because I have no idea about Webstart, unfortunately I can't comment on sblundy's recommendation :(.

systemsfault
+2  A: 

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.

Ran Biron
A: 

Hmm thanks Ran your suggestion also looks fine; but I searched for Java Webstart as sblundy recommended and I think think that it will do the job ;)

systemsfault