Saturday, November 10, 2012

Basic Applet Program in JAVA

A Java applet is an applet delivered to users in the form of Java bytecode. Java applets can run in a Web browser using a Java Virtual Machine (JVM), or in Sun's AppletViewer, a stand-alone tool for testing applets. Java applets were introduced in the first version of the Java language in 1995, and are written in programming languages that compile to Java bytecode, usually in Java, but also in other languages such as Jython, JRuby, or Eiffel.

Every applet must subclass or extends Applet Class. Below is the skeleton of a simple Java Applet or a very simple applet.
import java.applet.*;
import java.awt.*;

public class BasicApplet extends Applet {
    // This method is called once by the browser when it starts the applet.
    public void init() {
    }

    // This method is called whenever the page containing this applet is made visible.
    public void start() {
    }

    // This method is called whenever the page containing this applet is not visible.
    public void stop() {
    }

    // This method is called once when the browser destroys this applet.
    public void destroy() {
    }

    // This method is called whenever this applet needs to repaint itself.
    public void paint(Graphics g) {
    }
}
Here is an example of an HTML file that will cause the browser to load and start the applet.
<applet code="BasicApplet" width="100" height="100">
</applet>

0 comments:

Post a Comment

 

Blog Info

A Pakistani Website by Originative Systems

Total Pageviews

Tutorial Jinni Copyright © 2015 WoodMag is Modified by Originative Systems