Credits

Tuesday, February 25, 2014

Teaching Java Applets

 Java is a powerful object – oriented programming language which allows programmers to create applications for mobile and online among others.

One interesting feature of Java is the creation of applet, a small utility program that runs in a larger application like an HTML document. Java applet can be run using an HTML document or an Applet Viewer.

The following are the steps in writing and running Java applets:

1. Create a Java program of applet. The following is a sample code to display hello.

import java.applet.*; 
import java.awt.Color; 
import javax.swing.*; 
public class GreetApplet extends Applet { 

 JLabel greeting = new JLabel("I am an applet."); public 
void init() { 
 add(greeting); 
 setBackground(Color.PINK); 
 } } 

2. Compile the Java program to produce a bytecode.
3. If using an appletviewer, simply run the program otherwise write an HTML document  with the codes to embed an applet or object in general.
4. Double click the HTML document using any internet browser like Firefox Mozilla.

AddThis