CPSC1301 Computer Science 1 - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

CPSC1301 Computer Science 1

Description:

A Java applet is a program that is intended to transported over the Web and ... of the Java Software Development Kit (also through most IDEs including BlueJ) ... – PowerPoint PPT presentation

Number of Views:42
Avg rating:3.0/5.0
Slides: 9
Provided by: compu377
Category:

less

Transcript and Presenter's Notes

Title: CPSC1301 Computer Science 1


1
CPSC1301Computer Science 1
  • Introduction Applets

2
Applets
  • A Java application is a stand-alone program with
    a main method
  • A Java applet is a program that is intended to
    transported over the Web and executed using a web
    browser
  • An applet can also be executed using the
    appletviewer tool of the Java Software
    Development Kit (also through most IDEs including
    BlueJ)
  • An applet doesn't have a main method Instead,
    there are several special methods that serve
    specific purposes

3
Applets
  • The class that defines an applet extends the
    Applet class using inheritance
  • An applet is embedded into an HTML file using a
    tag that references the bytecode file of the
    applet
  • The bytecode version of the program is
    transported across the web and executed by a Java
    interpreter that is part of the browser

4
HTML file calling an Applet
  • lt!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"gt
  • ltHTMLgt
  • ltHEADgtltTITLEgtHello World Appletlt/TITLEgtlt/HEADgt
  • ltBODYgt
  • ltAPPLET CODEHelloWorld.class WIDTH200
    HEIGHT100gt
  • ALT "Applet could not be loaded
  • Sorry, it is time to upgrade your browser to a
    Java powered one.
  • lt/APPLETgt
  • lt/BODYgt
  • lt/HTMLgt

5
Applets
  • The paint method is typically used to draw the
    applets contents
  • The paint method accepts a parameter that is an
    object of the Graphics class
  • A Graphics object defines a graphics context on
    which we can draw shapes and text

6
Java Applet
  • import java.awt.Graphics
  • // Applet that displays Hello World on the screen
  • public class HelloWorld extends
    java.applet.Applet
  • public void paint(Graphics g)
  • g.drawString("Hello World", 5, 50)

7
Java Applet
  • import java.awt.Graphics
  • // Applet that displays Hello World on the screen
  • public class HelloWorld extends
    java.applet.Applet
  • public void paint(Graphics g)
  • g.drawString("Hello World", 5, 50)

8
Sample Java Applets
  • http//csc.colstate.edu/summers/NOTES/JAVA.HTM
  • http//csc.colstate.edu/summers/NOTES/java-example
    s.htm
Write a Comment
User Comments (0)
About PowerShow.com