Chapter 3 - Introduction to Java
Applets
Outline
3.1 Introduction
3.2 Sample Applets from the Java 2 Software
Development Kit
3.2.1 The TicTacToe Applet
3.2.2 The DrawTest Applet
3.2.3 The Java2D Applet
3.3 A Simple Java Applet: Drawing a String
3.3.1 Compiling and Executing WelcomeApplet
3.4 Two More Simple Applets: Drawing Strings and
Lines
3.5 Another Java Applet: Adding Floating-Point
Numbers
3.6 Viewing Applets in a Web Browser
3.6.1 Viewing Applets in Netscape Navigator 6
3.6.2 Viewing Applets in Other Browsers Using
the Java Plug-In
3.7 Java Applet Internet and World Wide Web
Resources
3.8
2002 (Optional
Prentice Hall. All rights reserved.Case Study) Thinking About Objects:
Identifying the Classes in a Problem Statement
, 2
3.1 Introduction
• Applet
– Program that runs in
• appletviewer (test utility for applets)
• Web browser (IE, Communicator)
– Executes when HTML (Hypertext Markup Language)
document containing applet is opened and downloaded
– Applications run in command windows
• Notes
– Mimic several features of Chapter 2 to reinforce them
– Focus on fundamental programming concepts first
• Explanations will come later
2002 Prentice Hall. All rights reserved.
, 3
3.2 Sample Applets from the Java
Software Development Kit
• Sample Applets
– Provided in Java 2 Software Development Kit (J2SDK)
– Source code included (.java files)
• Study and mimic source code to learn new features
• All programmers begin by mimicking existing programs
– Located in demo directory of J2SDK install
– Can download demos and J2SDK from
java.sun.com/products/jdk
2002 Prentice Hall. All rights reserved.
, 4
3.2.1 The TicTacToe Applet
• Running applets
– In command prompt, change to demo subdirectory of applet
cd c:\jdk1.3\demo\applets
cd appletDirectoryName
– There will be an HTML file used to execute applet
– Type appletviewer example1.html
• appletviewer loads the html file specified as its
command-line argument
• From the HTML file, determines which applet to load (more
section 3.3)
– Applet will run, Reload and Quit commands under
Applet menu
2002 Prentice Hall. All rights reserved.