Friday 10, February 2012
Welcome Guest, Register | Login  
      Home    |    Tutorials    |    Free Ebooks    |    Free Scripts    |    Articles    |    Blog     |    Forum    |    About Us    |    Contact Us

Applets in Java

An applet is a small program that is intended to be embedded inside another application such as a browser. The JApplet class must be the superclass of any applet that is to be embedded in a Web page or viewed by the Java Applet Viewer (appletviewer.exe). The JApplet class provides a standard interface between applets and their environment. JApplet hierarchy is as follows: 
java.lang.Object
java.awt.Component
java.awt.Container
java.awt.Panel
java.applet.Applet
javax.swing.JApplet

Applets Structure
- There is no main method.
- Two methods that are called automatically- init() and paint()
- The init method initializes variables and objects; if you don't have one you will inherit one from the JApplet class.
- Use paint to draw screen
- A lot of methods exist in JApplet class so the "extends" keyword inherits everything that the class has. In the above example JApplet is parent class and shellapplet is the subclass so use the keyword "extends" to create inheritance.
- You have to import JApplet and java.awt.Graphics (abstract windowing toolkit) to get Graphics to paint.
- All applets must inherit JApplet
- Use the "super" keyword in subclass to invoke method in the superclass.
- super.paint( g ); this says uses the paint method from JApplet in my paint class and I'm not adding anything to it.
Example:
import javax.swing.JApplet;
import java.awt.Graphics;

public class AnyApplet extends JApplet
{
        // declare variables here

      public void init( )
      {
               // data initialization goes here
      }

     public void paint( Graphics g )
    {
             super.paint( g );
    // your code goes here
   }
}

- The window gets drawn by invoking the paint class of the applet, which calls the superclass paint which draws the actual window you've given the size for.

- Other applet methods

  • repaint() – repaints when the window which the applet resides re-gains focus
     
  • stop() called when applet is no longer visible. Signature: public void stop(). Stopt is called by the browser or applet viewer to inform this applet that it should stop its execution. It is called when the Web page that contains this applet has been replaced by another page, and also just before the applet is to be destroyed. A subclass of JApplet should override this method if it has any operation that it wants to perform each time the Web page containing it is no longer visible. The implementation of stop method provided by the JApplet class does nothing.
     
  • start() called when the applet is visible. The signature for the start method is as follows: public void start(). Start is called by the browser or applet viewer to inform this applet that it should start its execution. It is called after the init method and each time the applet is revisited in a Web page. A subclass of JApplet should override this method if it has any operation that it wants to perform each time the Web page containing it is visited. The implementation of start method provided by the JApplet class does nothing.

  • estroy() when hosting window is closed (exit). Tha signature is as follows: public void destroy(). Destory method is called by the browser or applet viewer to inform this applet that it is being cultivated and that it should destroy any resources that it has allocated. The stop method will always be called before destroy. A subclass of JApplet should override this method if it has any operation that it wants to perform before it is destroyed. The implementation of destory method provided by the JApplet class does nothing.

 
     
   
Java Language Tutorial
 
  What is JAVA
What is JAVA
  Java an Object Oriented Language
Java an Object Oriented Language
  Java Keywords
Java Keywords
  Data Types
Data Types
  Java Operators
Java Operators
  Control Structure
Control Structure
  Arrays
Arrays
  Java Classes
Java Classes
  Java Constructors
Java Constructors
  Java Methods
Java Methods
  Java Method Overloading
Java Method Overloading
  Java Method Overriding
Java Method Overriding
  Java Nested Classes
Java Nested Classes
  Inheritance in Java
Inheritance in Java
  Interfaces in Java
Interfaces in Java
  Polymorphism in Java
Polymorphism in Java
  Exception Handling in Java
Exception Handling in Java
  Catching Exceptions
Catching Exceptions
  Embedding information in an exception object
Embedding information in an exception object
  The throws clause
The throws clause
  Checked and unchecked exceptions
Checked and unchecked exceptions
  The finally clause
The finally clause
  Applets in Java
Applets in Java
  Running an Applet
Running an Applet
 
 
 
Web Designing Tutorials
  HTML Tutorial
HTML Tutorial
  DHTML Tutorial
DHTML  Tutorial
  CSS Tutorial
CSS Tutorial
  XHTML Tutorial
XHTML Tutorial
 
Programming Languages Tutorials
  C Language Tutorial
C Language Tutorial
  C++ Tutorial
C++ Tutorial
  Java Language Tutorial
Java Language Tutorial
  Data Structure Theory Tutorial
Data Structure Theory Tutorial
 
Server Side Scripting Tutorials
  PHP Tutorial
PHP Tutorial
  SQL Tutorial
SQL Tutorial
  ASP Tutorial
ASP Tutorial
 
Client Side Scripting Tutorials
  JavaScript Tutorial
JavaScript Tutorial
  VBScript Tutorial
VBScript Tutorial
 
 
 
POPULAR E-BOOKS
 
Download Creating Wealth Boot Camp Ebook Creating Wealth Boot Camp
   
Download The Affiliate Marketers Master Guide Ebook The Affiliate Marketers Master Guide
   
Download Linux Internals (to the power of -1)  Ebook Linux Internals (to the power of -1)
   
Download Algorithms in the Real World: Lecture Notes  Ebook Algorithms in the Real World: Lecture Notes
   
Download  Your Ultimate Inspirational Guide Ebook Your Ultimate Inspirational Guide
   
 
Studiesinn.com © 2012 All Rights Reserved.
Website Designed & Developed by TechXprtz