Applet cum Application

Applet cum Application

Applet cum Application: A single program can be made to work as an Applet and also as an Application (that is, running the program as an Applet and Application). It is of Programming logic importance rather than realtime job.

In an applet, we can include a main() method that can be called implicitly by Java runtime environment. As usual, we write an <APPLET> tag to run this applet. This type of programs can easily be generated with Java tools like VJ++, JBuilder through their applet wizard.

The following program can be used both as Applet cum Application. Depending on the button clicked the background of the button changes.

When we use the program as an application, we call the init() method explicitly in the main() method. When worked as an applet, main() method is simply ignored by the browser and calls init() method implicitly. Screen outputs are given at the end of the program when it is worked as an applet and an application.

HTML file, File Name: AppletApplication.html

Applet cum Application

Applet cum Application

AppletApplication aa = new AppletApplication();
aa.init();

An object of current class AppletApplication, aa, is created to call the init() method. It is necessary to call the init() method explicitly, if the program runs an application. If the the program works as an applet, the init() method is called implicitly.

The HelperClass is the actual class that creates a frame. The HelperClass extends JFrame. The HelperClass includes only window closing mechanism.

f.getContentPane( ).add(aa,”Center”);

To the container, AppletApplication object aa, is added at the center, using an object of HelperClass, f, that extends JFrame.

====================Extra Reading on Applets==================
1. Applets Vs Applications
2. Applet to Application
3. Application to Applet

Leave a Reply

Your email address will not be published. Required fields are marked *