What's Java Hybrid - Applet + Application

What's Java Hybrid - Applet + Application?

A hybrid applet/application simply abstracts the initialization of two top-level containers, JFrame and JApplet. Examples are seen here, here and here.

Addendum: How does that work?

  • The first example exposes a factory method, createGUI(), and it adds the returned panel to the extant top-level container.
  • The second provides a static initContainer() method, passing the enclosing top-level container as a parameter.
  • The third creates a class Hybrid that has a static fireup() method and a WindowListener for error reporting.

Migrating applet to JWS


  1. Rework the GUI to appear in a JFrame.

    1. Split the project into separate Jars.
    2. If the Jars are common to a specific API, put them into a JNLP extension. That way they can be easily used by other projects.
  2. Launch the JFrame using JWS.

In answer to your specific questions:

Since applet is an old technology and I have problems with functionality (my applet is not signed) can you tell me exact benefits of switching my code to JWS (Java web start) and is the switch worth it?

Firstly, yes it is worth it.

Immediately any of the problems you might experience with applet/browser/JVM interaction are solved. The free floating app. is resizable, and more easily customizable as to frame title etc. The user can continue using the app. when the browser is closed. They can open the app. when offline, if it is configured to allow that.

In regard to the Jar updates, quoting the JWS tag Wiki:

Java Web Start (JWS) is the Oracle Corporation technology used to launch rich client (Swing, AWT, SWT) desktop applications directly from a network or internet link. It offers 'one click' installation for platforms that support Java.

JWS provides many appealing features including, but not limited to, splash screens, desktop integration, file associations, automatic update (including lazy downloads and programmatic control of updates), partitioning of natives & other resource downloads by platform, architecture or Java version, configuration of run-time environment (minimum J2SE version, run-time options, RAM etc.), easy management of common resources using extensions..

Onto..

If I switch to JWS will I be able to split my applet into several jar's that will be loaded and used by main jar (much like dlls)?

Yes. As many as needed, see above for the bare details.

If JWS isn't much better than applets, can you suggest me some other technology that use Swing?

I'd highly recommend to use JWS/Swing. So no, I do not have any other suggestions (that would approach being that good with as little effort).

Go ahead, try it out. I think you and your users will enjoy the change.

Is it ever appropriate to have a main method in an applet?

The main method does not have any special meaning to an applet.

Your professor is including it along with a few lines to fire up the class in a JFrame, to be able to run it from the command line too with a simple "java foobar" command. This as opposed to having to run the "appletviewer foobar" command which may have issues with being launched from another program like PowerPoint. it does not give the full Applet environment though, but the demonstration programs may be so simple, it doesn't matter.

Why he chose to do so instead of just presenting you with a big HTML page with the applets in, I do not know.



Related Topics



Leave a reply



Submit