Applet Basics:
All applets are subclasses of Applet. Therefore all applets have to import java applet. An Applet must also import java.awt. Recall in which AWT stands for the Abstract Windows Toolkit. Because all applets run in windows, it is must to involve support for that window. An Applet is not executed through the console based java runtime interpreter. Rather they are executed through either a Web browser or an applet viewer. A figure displays in this chapter were created along with the standard applet viewer, known as applet viewer, associated through the JDk. But you could use any applet viewer or browser you like.
Execution of an applet does not starts at main ( ). In fact few applets even have main ( ) methods. Alternatively, execution of an applet us begin and controlled with an entirely different mechanism, which will be explained shortly. Output to your applet's window is not performed through Syste.out.println ( ). Rather, it is handled with various AWT methods, such as drawstring ( ) which outputs a string to a specified X, Y location. An Input is also handled differently in which in an application.
At one an applet has been compiled it is involved in an HTML file using the APPLET tag. An applet will be executed through a java enabled web browser when it encounters the APPLET tag within the HTML file. For view and test an applet more conveniently, simply involve a comment at the head of your java source code file that contains the APPLET tag. This way your code is documented along with the necessary HTML statements needed through you applet and you can test the compiled applet through beginning the applet viewer along with your java source code file specified as the target. Above is an example of such a comment:
/*
<applet code="MyApplet" width =200 height = 60>
</applet>
*/
This comment holds an APPLET tag which will run an applet known as MyApplet in a window which is 200 pixel wide and 60 pixels high. Because the inclusion of an APPLET command makes testing applets simpler, all of the applets displays in this book will holds the suitable APPLET tag embedded in a comment.