Introduction to Java - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Introduction to Java

Description:

Free allocated. resources. Discard threads. JFrame and JApplet are both. subclasses of Container ... Can usually open JAR files using WinZip. Deploying Java Applets ... – PowerPoint PPT presentation

Number of Views:20
Avg rating:3.0/5.0
Slides: 19
Provided by: ETS38
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Java


1
Introduction to Java
  • April 10, 2008
  • David Goldschmidt, Ph.D.
  • goldschd_at_strose.edu

2
Java Applets
  • When an applet is loaded, the Web browser invokes
    the applets no-argument constructor
  • Web browser uses init(), start(), stop(),and
    destroy() methods to control the applet
  • By default, these methods do nothing
  • Override these methods in your applet such
    thatthe browser calls your code properly

3
Java Applets
  • Web browser calls init() when applet is first
    loaded (and again if applet is reloaded)
  • Override init() to
  • Set up UI components
  • Create new threads
  • Load images
  • Read parameter values
    from ltappletgt tag

4
Java Applets
  • After init() and on returning to a Web page, the
    Web browser calls the start() method
  • Override start() to
  • Reset UI components
  • Restart animations
  • Restart threads

5
Java Applets
  • When the user leaves the containing Web page, the
    Web browser calls the stop() method
  • Override stop() to
  • Stop animations
  • Suspend threads

6
Java Applets
  • When the user closes the containing Web page, the
    Web browser calls the destroy() method
  • Override destroy() to
  • Free allocatedresources
  • Discard threads

7
Applications vs. Applets
  • JFrame and JApplet are both subclasses of
    Container
  • All user interface components, layout
    managers,and event-handling features are the
    same
  • Applets require HTML for deployment
  • Both applications and applets require a JVM
  • (via JRE or Web browser plug-in)

8
Applications vs. Applets
  • Applications are invoked from astatic main()
    method by the JVM
  • Applets are run by Web browser
  • To provide a graphical environment
  • Applications require a frame (i.e. JFrame)
  • Applets require a Web browser

9
Applications vs. Applets
  • Applets have security restrictions
  • An applet is not allowed to read from orwrite to
    the file system of the Web browsers computer
  • An applet is not allowed to run any programson
    the Web browsers computer
  • An applet is not allowed to establish connections
    between the users computer and another computer
  • Except with the server on which the applet is
    stored

10
Applications vs. Applets
  • Converting an applet into an application is
    always possible (and usually mechanical)
  • Converting an application into an applet is
    sometimes possible, depending on whether security
    restrictions on applets are not violated

11
Tic Tac Toe
12
Tic Tac Toe
13
Bouncing Ball
  • Bouncing ball applet displays a ball bouncing
    within a panel
  • Two buttonssuspend andresume movement
  • Scroll bar controlsspeed
  • Run as either anapplet or application

14
Bouncing Ball
15
Overcoming Applet Restrictions
  • Security restrictions disallow applets from
    accessing local or network files
  • Applets can load image, audio, video,and other
    local or network files
  • Use the java.net.URL class to identifylocal
    files or files available via the Internet

16
Deploying Java Applets
  • A Java Archive ( JAR) file groups all project
    files into a single compressed file for
    deployment
  • Includes Java class files, images, audio files,
    etc.
  • Enables efficient deployment ofboth Java applets
    and applications
  • JAR files are based on the ZIP file format
  • Can usually open JAR files using WinZip

17
Deploying Java Applets
  • Use jar command from the Java SDK to create a
    Java archive file
  • jar -cvf TicTacToe.jar TicTacToe.class
    TicTacToeCell.class
  • Command-line arguments very similar to tar
  • Use -c to create a new JAR file
  • Use -v to specify verbose mode
  • Use -f to specify the name of the JAR file

18
Deploying Java Applets
  • Use the following HTML to deploy the JAR file
  • ltapplet
  • code"TicTacToe.class"
  • archive"TicTacToe.jar"
  • width"350"
  • height"200"gt
  • lt/appletgt
Write a Comment
User Comments (0)
About PowerShow.com