Tool to convert Java Swing application to applet

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

+4
source share
3 answers

Alternatively, you can start the launch of the current application. from the link using Java Web Start . There is no need for conversion and is much simpler than deploying an applet.

+3
source

If the original project creates a JFrame, you can just get the JPrame contentPane through

Container contentPane = myFrame.getContentPane(); 

And then add the JApplet as its contentPane, but you will lose the menu, etc.

For instance,

 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(); } } } 

It is better to have most of your GUI classes designed to create get go JPanels, so you don't come across this limitation.

+4
source

The tool consists of 4 lines of code:

 public class MyApplet extends Applet { public void start() { MyApplication.main(new String[0]); } } 

This applet will launch your application without command line arguments. The limitation here is that the applet will open its own window. It will not start in the browser window. It’s easy to run it in a browser in the general case, because the layout can be dynamic and can be created on the JFrame itself. So, you need some knowledge of the structure of the application in order to fully transfer it. The good news is that in most cases this is not so difficult. Just enter the code that adds the components to the JFrame using the applet itself, which extends the panel and therefore is a container.

If your application receives parameters, you must implement the applet's init() method.

+2
source

Source: https://habr.com/ru/post/1402489/


All Articles