Applets are programs which run on web browser and Application means the stand alone program in a computer. In Java we can convert Applets to Application and Application to Applet. Using this idea we can make any program run as either applet or as an application. Following are the steps for converting applets to Application.
Step 1:
Change init() method's name to the constructor. Java Applets contains init() method which is used for initializing the applet, this method should be changed to constructor for that class. This involves removing void(return type) of init(), because constructor don't return anything.
e.g. public void init() should be changed to
Application()
Step 2:
Replace "extends Applet" with "extends Frame" for the class.
e.g. public class Application extends Applet should be changed to
public class Application extends Frame
Step 3:
Create new main() method. Create object of the class in that method and set size of the frame and different properties as follows.
public static void main
(String[] args
)
{
Application app=new Application();
app.setSize(400,400);
app.setVisible(true);
}
Step 4:
Delete "import" statement for class Applet.
Step 5:
Add WindowListener's method to handle window events. Add implements WindowListener to the class declaration as follows.
Add code to register WindowListener to the frame.
this.addWindowListener(this);// code for handling window event is present in the same class.
Add implementation for all the methods of the WindowListener interface.
{
dispose();
System.
exit(0);// normal exit of program
}
public void windowOpened
(WindowEvent e
){}// simply add definition if no code to be added.
Step 6:
Remove getAudioClip(), getImage(),getCodeBase(), getDocumentBase() methods as these are used with Applet only.