Monday, 27 August 2012

Easy steps for Applet program


Applet

 Applet is an application running on web browser. it is designed to be transmitted over the internet and running always on client machine.

Web Architecture

     

Applet are small application that are accessed on a Internet server, transported over the Internet, automatically installed & run as part of web document.

Hierarchy of Applet


Applet Life Cycle

init() :this is for initialization as like constructor ,it is automatically called by  system itself.
start() : this methods automatically calls when java calls init method
stop() : this method automatically calls when user moves off the page on which the applet sits.
destroy() : Java is guaranted to call this method when the browser shuts down normally.
paint(Graphics g) : The paint( ) method is called each time your applet’s output must be redrawn.

Simple Applet Program

Follow the steps for applet program

1.     Write the Simple program
              import java.awt.*;
             import java.applet.*;
            class MyApplet extends Applet
              {
                        public void paint (Graphics g)
                        {
                         g.drawString ("Hello World", 25, 50);
                        }
             }
2.     Save this program as MyApplet.java,
3.     Compile Applet program by using command javac MyApplet.java
4.     After that do the HTML code as like below
<html>
<head>This is Applet Program</head>
<body>
<applet code="MyApplet" width=200 height=60>
</applet>
</body>
</html>
    5. Save this html code as Applet.html.and open it into web browser.See  output.

Restriction of Applet


  1. Applet can never run any local executable program.
  2. Applet can’t communicate with an internet site other than the one that served the web page that included the applet.
  3. Applet can’t read/write files on user’s file system.
  4. All windows popped by an applet carry a warning message.
  5. Applet can never find any info about the local computer.


If any problem persist use comment line to share your problem.

ShareThis

Related Posts Plugin for WordPress, Blogger...