Presentation is loading. Please wait.

Presentation is loading. Please wait.

Applets and HTML Chapter 13.

Similar presentations


Presentation on theme: "Applets and HTML Chapter 13."— Presentation transcript:

1 Applets and HTML Chapter 13

2 Introduction to Applets
An applet is a “small application” or a “little Java program.” Applets are Java programs that are typically displayed on a Website and viewed over the Internet. An applet can also be run as a stand-alone program on a computer which is not connected to the Internet. Chapter 13

3 Running an Applet Applets are compiled the same way other Java classes are compiled. However, the normal way to run an applet is as part of a Web document. The applet then is viewed using a Web browser. An applet can also be viewed using an applet viewer which is a program designed to run an applet as a stand-alone program. Chapter 13

4 Programming Example: An Adder Applet
class AdderApplet Chapter 13

5 Placing an Applet in an HTML Document
To display the adder window created by class AdderApplet, place the following command in an HTML document: <applet code=“AdderApplet.class” width=400 height=200> </applet> (Actually “.class” is optional. code=“AdderApplet” works just as well) Chapter 13

6 Placing an Applet in an HTML Document, cont.
This command assumes that the HTML file and the file AdderApplet.class are in the same directory. Otherwise, a relative or absolute path name to AdderApplet.class is needed. Chapter 13

7 Placing an Applet in an HTML Document, cont.
Chapter 13

8 Placing an Applet in an HTML Document, cont.
Chapter 13

9 Using an Old Web Browser
A Web browser must be set up to run applets. Web browsers do not use the same Java interpreter used to run Java applications. Older Web browsers (yours or someone else’s who may want to view your HTML document) may not be able to run applets from an HTML document. Chapter 13

10 Using an Old Web Browser, cont.
Furthermore, Java updates for browsers typically lag core Java language updates. Using the older Applet class sometimes can remedy the problem. These problems do not exist if you are running applets from the applet viewer using a recent version of Java. Chapter 13

11 Applets and Security Your applet is a program that may be run on someone else’s computer. Worse, someone else’s applet might be run on your computer! Furthermore, you don’t know that an HTML page contains an applet until you load it into your browser, and then it is too late to reject the applet; it is already stored on your computer. Chapter 13

12 Applets and Security, cont.
Someone else’s program running on your computer creates serious security concerns. Will it leave a virus? Will it alter your files or read confidential information? Will it corrupt your operating system? Applets cannot do any of these things (at least not easily). Chapter 13

13 Applets and Security, cont.
Applets cannot run your programs, nor can they read from or write to files on your computer (unless the applet originated on your computer). Chapter 13


Download ppt "Applets and HTML Chapter 13."

Similar presentations


Ads by Google