Create a program that runs on the desktop and can also run as an applet

0

Good, I have to make a program that can be executed both in desktop and in applet, using mvc. The question is that I do not know how to attack the program ... I have to create the main, in the instance of 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 is executed in desktop or in the browser, it starts in one place or another ?

Thank you.

    
asked by Josuee 11.10.2016 в 14:00
source

2 answers

1
  • The appletviewer command lets you run an applet like desktop application.

  • Create two versions of the program. It is not as complicated as you seem if you organize the program well (the logic separated from the presentation); you have both a class that implements Applet and a class with main that launches the GUI; both simply call the same classes that will be those that have the functionality ("chicha") of the program. Since you have to indicate which class you are running anyway, you can have both classes in the same project.

    An important issue to keep in mind is that, unless you sign it properly, an applet will have important security restrictions at the time of execution.

A third option that is not exactly what you ask but that can help is Java Web Start, you can look for it to see if it helps you.

    
answered by 11.10.2016 / 15:07
source
0

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

  • the distribution (and consequently the update) of program.
  • the launch of the program.
  • If the distribution is not a problem (that is, you have no problem walking around in a jar file via mail or USB sticks) the simplest trick for a desktop is in the Manifest of the jar (Main-Class).

    JNLP covers both distribution and launch for desktop and web.

        
    answered by 11.10.2016 в 18:22