Clientside Dynamic Programming: Applet - PowerPoint PPT Presentation

1 / 7
About This Presentation
Title:

Clientside Dynamic Programming: Applet

Description:

How to create an Applet? Ex1: A simple ... The lifetime of an applet depends on the web page. When a web page is loaded, the applet is initialized and started. ... – PowerPoint PPT presentation

Number of Views:24
Avg rating:3.0/5.0
Slides: 8
Provided by: compu369
Category:

less

Transcript and Presenter's Notes

Title: Clientside Dynamic Programming: Applet


1
Client-side Dynamic Programming Applet
  • Dan Wang

2
Introduction
  • What is Applet?
  • Applet is a software component that runs in the
    browser
  • Applet is not a program
  • It cannot run independently.
  • It must run in a container (browser).
  • Applet is not a subroutine or a function.
  • It can implement a complete web component.
  • Applets can enhance the capability of interacting
    between the user and their host program.

3
Introduction
  • How to create an Applet?
  • Ex1 A simple applet Hello, World!
  • Generate the bytecode FirstApplet.class
  • javac FirstApplet.java
  • Use HTML document to embed the Applet

import java.applet. import java.awt. public
class FirstApplet extends Applet public void
paint(Graphics g) g.drawString("Hello,
World!", 25, 50)
4
Embedded in HTML Document
  • HTML uses ltappletgt tags to embed an applet
  • ltapplet codeapplet-name.class width
    height codebaseapplet-URL namegt
  • ltparam namepar1 valueval1gt
  • ltparam namepar2 valueval2gt
  • lt/appletgt

5
Lifetime of an Applet
  • The lifetime of an applet depends on the web
    page.
  • When a web page is loaded, the applet is
    initialized and started.
  • When the user leaves the web page, the applet
    stops.
  • When the browser is closed, the applet is
    finalized.

Start()
Stop()
Final()
Init()
6
Execution of Applet
  • When the web page with an applet is loaded, the
    browser will do the following
  • Search the bytecode of the applet class defined
    in the ltappletgt tag. The URL location is
    determined by the codebase attribute
  • Load the bytecode to the user machine
  • Create an instance of the applet class
  • Call init() to initialize the applet instance
  • Call start() to execute the instance
  • When leave the page, call stop() to stop the
    execution
  • When return to the page again, call start() to
    restore the execution.
  • When the browser is closed, the applet is
    finalized.

Start()
Stop()
Final()
Init()
7
More Examples
  • Ex1 A simple applet Hello, World!
  • Source file FirstApplet.java
  • Ex2 Drawing something in an applet
  • Source file SecondApplet.java
  • Ex3 Processing event in an applet
  • Source file EventTester.java
  • Ex4 Get parameters from HTML file
  • Source file ColorScribble.java
  • Ex5 Add a button in an applet
  • Source file ClearableScribble.java
Write a Comment
User Comments (0)
About PowerShow.com