Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tool to convert a Java Swing application into applet

Tags:

java

applet

swing

I have a big Swing project. Is there any tool that convert the Swing application jar file into an applet?

like image 921
confucius Avatar asked Jan 17 '23 04:01

confucius


1 Answers

If the original project creates a JFrame, you could simply get the JFrame's contentPane via

Container contentPane = myFrame.getContentPane();

And then add it the JApplet's as its contentPane, but you would lose menus and such.

For e.g.,

public class MyApplet extends JApplet {

   @Override
   public void init() {
      try {
         SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
               JFrame myFrame = new MyFrame("Frame");
               Container contentPane = myFrame.getContentPane();
               setContentPane(contentPane);
            }
         });
      } catch (InterruptedException e) {
         e.printStackTrace();
      } catch (InvocationTargetException e) {
         e.printStackTrace();
      }
   }
}

Better to have most of your GUI classes geared to create JPanels from the get go so you don't run into this limitation.

like image 174
Hovercraft Full Of Eels Avatar answered Feb 04 '23 09:02

Hovercraft Full Of Eels