This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
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


Win a copy of Elasticsearch in Action this week in the Big Data forum!
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: 2585
    
  55
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: 2585
    
  55
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
Rancher

Joined: Mar 22, 2005
Posts: 42954
    
  73
This may be of interest: https://www.coderanch.com/how-to/java/AppletsFaq#application
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: 2585
    
  55
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.
 
 
subject: Converting an Application to an Applet