A Simple Java Applet - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

A Simple Java Applet

Description:

In this lecture we will create and run a simple Java applet. ... import java.awt.*; import java.applet.*; public class AppletName extends Applet ... – PowerPoint PPT presentation

Number of Views:89
Avg rating:3.0/5.0
Slides: 12
Provided by: duanes
Category:
Tags: applet | java | reimport | simple

less

Transcript and Presenter's Notes

Title: A Simple Java Applet


1
A Simple Java Applet
  • Cmput 114 Section A3 Fall 2005
  • Lecture 2
  • Department of Computing Science
  • University of Alberta

2
About This Lecture
  • In this lecture we will create and run a simple
    Java applet.
  • We wont try to understand any of the code.
  • Instead we will simply concentrate on the
    mechanics of using the programming environment to
    create and run the applet.

3
Outline
  • Kinds of Java programs
  • Applet template
  • A simple applet Applet0
  • Running applets from a Browser
  • Eclipse applet demonstration

4
Kinds of Java Programs
  • Recall the three kinds of Java programs
  • Applications
  • Applets
  • Libraries
  • An application is a Java program that is run by
    using a Java interpreter program.
  • An applet is a Java program that is run by a
    Java-enabled web browser.
  • A library is a set of Java classes that can be
    used by another Java program.

5
Java Applet Template
  • import java.awt.
  • import java.applet.
  • public class AppletName extends Applet
  • /
  • Applet description.
  • /
  • public void paint(Graphics graphics)
  • / applet display statements go here. /

put display statements here
6
Applet Applet0
  • import java.awt.
  • import java.applet.
  • public class Applet0 extends Applet
  • /
  • This is our first applet.
  • /
  • public void paint(Graphics graphics)
  • / Display myself on the given Graphics /
  • graphics.drawString(This is an applet., 10,
    50)

x and y coordinates of upper left corner of the
String
7
Applet0 Output in Applet Viewer
8
HTML Documents
  • A web browser runs an Applet by first loading a
    document written in a language called HTML
    (HyperText Markup Language).
  • HTML defines the meanings of tags that are added
    to document text, which specify the format of the
    document and links to other documents.
  • One of the tags in the HTML file tells the
    browser to load an applet.

9
Applet0.html
start of html
  • ltHTMLgt
  • ltHEADgt
  • ltTITLEgtApplet0lt/TITLEgt
  • lt/HEADgt
  • ltBODYgt
  • ltHRgt
  • ltAPPLET
  • CODEApplet0.class
  • WIDTH300 HEIGHT60gt
  • lt/APPLETgt
  • ltHRgt
  • lt/BODYgt
  • lt/HTMLgt

start of header information
the web page title
start of web page content
a horizontal line (rule)
load an applet
from this file
in a box this big
10
Applet0 Output in a Browser
11
Demonstration Applet
  • Start Eclipse.
  • Create a new project called Applet0.
  • Create a class called Applet, setting superclass
    to java.applet.Applet.
  • Edit the code.
  • Save the source file as Applet0.java.
  • Compile (Build) to create Applet0.class file.
  • Run from Eclipse.
  • Edit HTML file - Applet0.html.
  • Load html file from Browser.
Write a Comment
User Comments (0)
About PowerShow.com