The examples below illustrate the basic structures for a Java Application and an Applet. Reference to the Java API may be useful.
Application
Minimal Application
Below is the minimal application framework.
public class Application {
public Application( ) { // constructor
super( );
} // end constructor
public static void main(String args[]) {
} // end main
} // end application
Example Application
Below is a "Hello, World!" level application.
public class BasicApplication {
public static void main(String args[]) {
if ( args.length != 0 ) {
for ( int i=0; i < args.length; i++ )
System.out.println( args[i] );
}
else System.out.println ( "Hello, World1" );
} // end main
} // end BasicApplication
Applet
Minimal Applet
Below is a minimal applet framework.
import java.applet.Applet;
public class MinimalApplet extends Applet {
public void init ( ) {
} // end init
public void start ( ) {
} // end start
public void stop ( ) {
} // end stop
public void destroy ( ) {
} // end destroy
} // end MinimalApplet
Minimal Applet
Below is a "Hello, World!" level applet.
import java.awt.*;
import java.applet.Applet;
public class BasicApplet extends Applet {
private Label label;
public void init ( ) {
System.out.println("In BasicApplet.init");
} // end init
public void start ( ) {
label = new Label ("BasicApplet ");
System.out.println("In BasicApplet.start");
add (label);
} // end start
public void stop ( ) {
remove (label);
System.out.println("In BasicApplet.stop");
} // end stop
public void destroy ( ) {
System.out.println("In BasicApplet.destroy");
hide( );
} // end destroy
} // end BasicApplet
Applet HTML
<HEAD>
<TITLE>BasicApplet</TITLE>
</HEAD>
<BODY>
<H3>BasicApplet</H3>
<HR>
<APPLET code="BasicApplet.class" width=400 height=200>
</APPLET >
</BODY>