Wednesday, August 3, 2011

First Java Applet

(1) Create a file JavaProgramming.java with the source code below and compile it.

Source Code:

/*
*JavaProgramming
*Applet
*/

//imports the graphics class
import java.awt.Graphics;

//extends class characteristics and capabilities
public class JavaProgramming extends java.applet.Applet {

public void paint(Graphics g)
{
//tells the applet to print out the string quoted in a specified (x=10,y=50)
coordinate
g.drawString("Welcome to Java Programming!!" ,10, 50);
}

}

(2) In order to run the Applet, you would need to write HTML doc and include the applet within it.Alternatively used the sample below and save it as JavaProgramming.html.

Source Code:



(3)To run the applet. Type the following command prompt:

appletviewer JavaProgramming.html

Congratulations!! You've just run your first basic Applet.

No comments:

Post a Comment