GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes Converting an Application to an Applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Converting an Application to an Applet" Watch "Converting an Application to an Applet" New topic
Author

Converting an Application to an Applet

Tim Alvord
Greenhorn

Joined: Jan 24, 2013
Posts: 23
Is there some documentation somewhere on Converting a Java Swing Application into a Java Applet?
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2301
    
  49
It really depends on how the application has been written and what it does. If you have a way of starting the application and getting the GUI's main panel then you can just do:

If the application does lots of background processing (ie animations) which you want to stop when the browser is hidden etc then you will also have to override the stop() and start() methods and take action accordingly.
Tim Alvord
Greenhorn

Joined: Jan 24, 2013
Posts: 23
Tony Docherty,
That worked pretty good inside of the Eclipse IDE. For some reason setting the background color of the Applet to black didn't work. It was displayed in Gray.

When I try and run the Applet from a browser, all I get is a blank Gray box the size of the Applet... Any ideas?
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2301
    
  49
For some reason setting the background color of the Applet to black didn't work. It was displayed in Gray.

You probably should be setting the background colour of the JPanel.

When I try and run the Applet from a browser, all I get is a blank Gray box the size of the Applet... Any ideas?

Not without seeing what you are doing ie the code, html etc
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42032
    
  64
This may be of interest: https://www.coderanch.com/how-to/java/AppletsFaq#application


Ping & DNS - my free Android networking tools app
Tim Alvord
Greenhorn

Joined: Jan 24, 2013
Posts: 23
Tony,
I am setting both the JFrame and the Pane background color to Black.

Here's what I've got:


Like I said before it works in Eclipse more or less, but not in the browser...
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2301
    
  49
Why are you getting a new instance of the applet and adding that to the applet content pane?

You need to set the background of the highest level opaque component that provides the background for your app (probably a JPanel). I should go back to running the application as a stand-alone app and see if you can change the background colour of that.
 
wood burning stoves
 
subject: Converting an Application to an Applet