Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 6 Applets and HTML  Overview  HTML tags for Applets  Applet Life Cycle  Applet Class  JAR files.

Similar presentations


Presentation on theme: "Chapter 6 Applets and HTML  Overview  HTML tags for Applets  Applet Life Cycle  Applet Class  JAR files."— Presentation transcript:

1 Chapter 6 Applets and HTML  Overview  HTML tags for Applets  Applet Life Cycle  Applet Class  JAR files

2 Overview  application: A class containing a method that is declared: static public void main(String [] args)  applet: A class derived from java.applet.Applet  java.lang.Applet is not an interface. Thus single inheritance says that your applet may not extend any other classes.  Intent of applet design was to give dynamic content to Web pages by running on a virtual machine built into a web browser.

3 Overview  Web browser’s VM uses a security manager to deny any machine operations that could do anything harmful, and restricts access within the applet to the web server (to dynamically download classes as needed)  Web servers/clients : –client requests browser to receive a page using a URL that specifies the protocol (http), a location ( ext-studies.haifa.ac.il ), a port, and a page http://ext-studies.haifa.ac.il/bina/index.html –index.html is a page indicating presentation formatting (html) to a browser.

4 HTML Tags for Applet  Line breaks and indentation in a web page have no meaning and exist solely for human readability.  Browsers format web pages using tags which are indicated by surrounding a name in and closed with a tag  tags such as indicate a new paragraph (no required since the next tag closes the previous )  Tags visible link allow a web page to request the download of yet another page.

5 HTML Tags for Applet  For our purposes, we are interested only in putting java programs on HTML pages.  Applet tags were introduced into HTML to indicate the inclusion of a java program.  A minimal HTML page containing an applet would be:

6 More Tags Slide Viewer Applet Images

7 Applet Life Cycle  the browser downloads the class in the applet tag and calls an init() method. This is where you initialize your program  the browser calls the start() method. This method starts your program running, and will be called whenever the applet needs restarting.  The stop() method is called when the web page is replaced by another page.  Before a browser terminates an applet it will call the destroy() method of the applet.  It is not required that methods of your applet override any of these methods.

8 Applet Class  Your applets extend Applet which has methods other than start, stop ….methods providing functionality that is useful to programs in web pages.  Every Applet is a Panel which is a Container which is a Component which is an Object meaning that applets inherit methods from these classes as well (e.g. paint() )

9 Applet Useful Methods  Those that interact with browser –URL getDocumentBase() returns a URL object that has methods that allow you to deal with the base of the web page. –URL getCodeBase() contains the URL of the applet, which could differ from the Document base. –String getParameter(String name) returns the value of a parameter in the applet tag.

10 More Methods  Those that provide Media Support –Image getImage(URL) –Image getImage(URL,name) –AudioClip getAudioClip(URL url),.. –void play(URL), …

11 More Methods  Those that interact with the browser environment –AppletContext getAppletContext() returns an instance of the AppletContext class that allows an applet to affect its environment in limited ways – void showDocument(URL) replaces the current web page with the URL. –...

12 More Methods  Those that provide applet information – String getAppletInfo() –…  Of the methods in ancestor classes, the paint(Graphics g) method is probably the most useful, as overriding this method gives the programmar a Graphics object that can be used to draw in the applet.

13 Current Applet Issues  Classes used in applet programs are loaded individually in order as needed.  This is both a strength – (don’t need 100 Mbytes of class so never loaded)  and a weakness –( loading a class when needed takes a performance hit)

14 Solutions  load a basic collection of classes to get started, and while the user is interacting with the basic interface,other classes in another thread with lower priority can download other classes.  When you wish to load a large number of classes at one time, use JAR files.

15 JAR Files  Utility named jar creates a gzipped file of classes. (Jar files can be dealt with by utilities such as winzip) but have the command line semantics of “jar”  in the command line : jar cf name.jar *.class image.gif sound.au  in the HTML file:


Download ppt "Chapter 6 Applets and HTML  Overview  HTML tags for Applets  Applet Life Cycle  Applet Class  JAR files."

Similar presentations


Ads by Google