0 votes

Create a program that runs on the desktop and at the same time can run as an applet

Good, I have to make a program that can be executed both in desktop and applet, using mvc. The question is that I don't know how to attack the program? Should I create the main, instantiate the constructor, and at the same time create a class that extends the applet in which the constructor is also instantiated, and depending on whether it runs on the desktop or in the browser start on one site or another?

Thank you.


SJuan76 Points 7859
  • The command appletviewer allows you to run an applet as a desktop application.

  • Create two versions of the program. It's not as complicated as you seem to think if you organize the program well (the logic separate from the presentation); you have both a class that implements Applet as a class with the main that launches the GUI; the two simply call the same classes that will have the functionality ("the gist") of the program. Since you have to indicate which class you run anyway, you can have both classes in the same project.

    An important thing to keep in mind is that, unless you sign it properly, an applet will have significant security restrictions when it is executed.

A third option that is not exactly what you are asking for but may help is Java Web Start, you can look it up to see if it works for you.


Sal Points 514

In order not to create two versions, the concept you are looking for is called Entry-Point. Consider that they are two different problems:

  1. distribution (and consequently the updating) of the program. program.
  2. the launch of the program.

If distribution is not a problem (i.e., you don't mind rolling a jar file via mail or USB sticks) the simplest desktop trick is in the jar's Manifest (Main-Class).

JNLP covers both distribution and release for desktop and web.


HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by: