itft- applet in java

13
APPLET PROGRAMMING

Upload: atul-sehdev

Post on 19-May-2015

965 views

Category:

Education


1 download

DESCRIPTION

introduction to Applets, life cycle of applets, methods of applets, examples,embedding apllets in html files, compiling and running of applets with appletviewer

TRANSCRIPT

Page 1: ITFT- Applet in java

APPLET PROGRAMMING

Page 2: ITFT- Applet in java

2

IntroductionWe can write two kinds of program in JAVA

they are

APPLICATION BASED

APPLET BASED

The application based programs are the programs which are used in the places such as super markets, hospitals etc.

The applet based program is used for the development of Graphics .

Page 3: ITFT- Applet in java

APPLETSAPPLET is a small application

embedded in HTML page, which is

accessed & transported over the

Internet , automatically installed

into client machines and run as

part of web page.

Applet are great for creating

dynamic & interactive web

applications .

Applet is a self executing program .

Page 4: ITFT- Applet in java

Init() : initializes applet before loading.

Start(): starts execution of applet

Paint(): graphics created

Stop(): stops any operation

Destroy(): applet completes execution

To create applet , Applet class from java. applet

package should be imported so tht they are

automatically run by any applet program

Applet Life Cycle

Page 5: ITFT- Applet in java
Page 6: ITFT- Applet in java

The init() method

The init method is invoked after the applet is created or recreated.

A subclass of Applet should overrides this method if the subclass has an initialization to perform.

Usually includes creating new thread, loading images, setting up GUI components

Page 7: ITFT- Applet in java

Start() method

The start method is invoked after the init

method.

Called whenever the applet become active

A subclass of Applet overrides this method

if it has any operation that needs to be

performed whenever the webpage is

visited.

An applet with animation might use the start

method to resume animation

Page 8: ITFT- Applet in java

Stop() method

The stop method is the opposite of the start method.

Is invoked when the user leave the page.

A subclass of Applet overrides this method if it has any operation that needs to be performed

When the user leaves the page, any threads that applet has started but not completed will continue to run. You should override the stop method to suspend the running threads so that the applet does not take up system resources when it is inactive

Page 9: ITFT- Applet in java

Destroy() method

The destroy() method is invoked when the browser exits normally to inform the applet that is no longer needed and should release any resources it has allocated.

The stop method is always called before the destroy method

A subclass of Applet overrides this method if it has any operation that needs to be performed before it is destroyed

Usually you won’t need to override this method unless you wish to release specific resources, such as threads that the applet created

Page 10: ITFT- Applet in java

A SIMPLE APPLETimport java.applet.*;import java.awt.*;

public class MyApplet extends Applet{

public void paint (Graphics g){

g.drawString ("Hi this is my first Applet program", 25, 50);}

}

Page 11: ITFT- Applet in java

11

Adding applet to Html File

• You can only run an applet in an HTML page

• The HTML looks something like this:• <html>

<body><h1>Myapplet Applet</h1><applet code=“Myapplet.class"

width="250" height="200"> </applet>

</body></html>

Page 12: ITFT- Applet in java

Running Applet in AppletViewer• Compiling

javac Myapplet.java

• Running

appletviewer Myapplet.java

Applet viewer is a command line program to run Java applets.

Page 13: ITFT- Applet in java