java Applet Introduction

7
Applet Class Applet Life cycle Applet Skeleton Applet Status Window

Transcript of java Applet Introduction

Page 1: java Applet Introduction

Applet ClassApplet Life cycle Applet Skeleton

Applet Status Window

Page 2: java Applet Introduction

Applet Class

• An applet is a small Internet-based program written in Java, a programming language for the Web, which can be downloaded by any computer

• The applet is also able to run in HTML

What Applets are?• Applets are dynamic (animations and graphics).• Applets are interactive programs (via GUI components).

Features of an Applet• Provides facility for frames• Event handling facility and user Interaction• GUI user interface• Graphics and multimedia

Page 3: java Applet Introduction
Page 4: java Applet Introduction

Sample program of Appletimport java.applet.*;import java.awt.*;import java.applet.Applet;public class Applet_Class extends Applet {

public void paint(Graphics g){

g.drawString("hello world",20,20);}

}

Page 5: java Applet Introduction

Applet Skeleton

Init()• The init method is the first method to be called.• Used for Initialize variables.• Only once during the run time of appletStart()• It is called after the init()• Start method called each time of an applet’s displayed on screen.Paint()• Paint method is called each time your applet’s output must be redarwn.Stop()• Stop method is called when a browser close.• The running applet will get stop • The applet is in suspend stateDestroy()• This method remove the applet completely from memory

Page 6: java Applet Introduction

import java.applet.*; import java.awt.*; import java.applet.Applet;public class Applet_Class extends Applet { private static int initcall, startcall, paintcall, stopcall, destroycall; public void init() { setBackground(Color.cyan); setForeground(Color.red); initcall=initcall+1; } public void start() { startcall=startcall+1; } public void stop() { stopcall=stopcall+1; g.drawString("stop method", 0,1); } public void destroy() { destroycall=destroycall+1; } public void paint(Graphics g) { paintcall=paintcall+1; g.drawString("init Method is called for : "+initcall,0,14); g.drawString("start Method is called for : "+startcall,0,30); g.drawString("paint Method is called for : "+paintcall,0,46); g.drawString("stop Method is called for : "+stopcall,0,62); g.drawString("destroy Method is called for : "+destroycall,0,78); showStatus("Demo of Applet Life Cycle"); }}

Page 7: java Applet Introduction

Using the Status Windowimport java.applet.*;import java.awt.*;import java.applet.Applet;public class Applet_Class extends Applet { public void init()

{ }public void paint(Graphics g){ g.drawString("hellow see status at bottom", 40,40);showStatus("yugandhar");}

}