adhitz

counter

hit counter

on

adhitz

Friday, May 6, 2011

Standard Applet Methods

The first step in the creation of an applet is to make it a subclass of JApplet, a class that's part of the Swing package, javax.swing. An applet is treated as a visual window inside a web page, so JApplet is part of Swing alongside clickable buttons, scrollbars, and other components of a program's user interface.
JApplet is a subclass of Applet, a class in the java.applet package. Being part of this hierarchy enables the applets you write to use all the behavior and attributes they need to be run as part of a web page. Before you begin writing any other statements in your applets, they will be able to interact with a web browser, load and unload themselves, redraw their window in response to changes in the browser window, and handle other necessary tasks.
In applications, programs begin running with the first statement inside the main() block statement and end with the last closing bracket (}) that closes out the block. There is no main() method in a Java applet, so there is no set starting place for the program. Instead, an applet has a group of standard methods that are handled in response to specific events as the applet runs.
The following are the events that could prompt one of the applet methods to be handled:
  • The program is loaded for the first time, which causes the applet's init() and start() methods to be called.
  • Something happens that requires the applet window to be redisplayed, which causes the applet's paint() method to be called.
  • The program is stopped by the browser, which calls the applet's stop() method.
  • The program restarts after a stop, which calls the start() method.
  • The program is unloaded as it finishes running, which calls the destroy() method.
The following is an example of a bare-bones applet:
public class Skeleton extends javax.swing.JApplet {

    // program will go here

}


Unlike applications, applet class files must be public because the JApplet class is also public. (If your applet uses other class files of your own creation, they do not have to be declared public.)
Your applet's class inherits all the methods that are handled automatically when needed: init(), paint(), start(), stop(), and destroy(). However, none of these methods do anything. If you want something to happen in an applet, you have to override these methods with new versions in your applet program.

0 comments:

Post a Comment

Popular Posts

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Justin Bieber, Gold Price in India