Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 12: Accessing the Web URL (Uniform Resource Locator) class Applet methods –for audio clips –for images –context interface.

Similar presentations


Presentation on theme: "Chapter 12: Accessing the Web URL (Uniform Resource Locator) class Applet methods –for audio clips –for images –context interface."— Presentation transcript:

1 Chapter 12: Accessing the Web URL (Uniform Resource Locator) class Applet methods –for audio clips –for images –context interface

2 Living on the Web An HTML document contains reference to an Applet, not the applet code itself Code retrieved by URL URL (Uniform Resource Locator) –essentially a web addressing system –URL: protocol://hostname/pathname/filename

3 URL Parts Protocols –http - hypertext transfer protocol –ftp - file transfer protocol –gopher - use gopher transfer mechanism –file - local file Host - series of domains separated by “.” –www.d.umn.edu –may have a port number: www.d.umn.edu:8080 Path and File names tend to be somewhat system specific

4 URL Class In java.net package Constructors: URL(String name) - uses name to construct URL(URL base, String relative) - constructs URL relative to base URL is “http://www.d.umn.edu/~rmaclin/home.html”, if relative is “index.html” then this constructs URL “http://www.d.umn.edu/~rmaclin/index.html” URL(String protocol, String host, String file) - creates URL from combined parts URL(String protocol, String host, int port, String file)

5 URL Class Methods: String getProtocol() - string describing protocol String getHost() - string describing host int getPort() - port # String getFile() - string describing path/filename

6 Other Methods from Applet URL getCodeBase() - get URL of directory containing applet’s.class file URL getDocumentBase() - get URL of current HTML document AudioClip getAudioClip(URL u) - retrieves AudioClip interface associated with URL AudioClip getAudioClip(URL u, String relative) Image getImage(URL u) - retrieves image Image getImage(URL u, String relative)

7 More Applet Methods void play(URL u) - play AudioClip directly void play(URL u, String relative) AppletContext getAppletContext() - returns context interface associated with window (more later) void showStatus(String message) - put message on browser’s status bar

8 Applet Parameters In HTML tag can have params: <APPLET CODE = “MyApp.class” WIDTH = 500 HEIGHT = 300 Can access: String getParameter(String name) - returns value of name (or null if none)

9 AppletContext Interface Interface implemented by browser, allows you to interfact with browser Useful methods: Applet getApplet(String name) - gives access to other Applets running - can send messages void showDocument(URL u) - asks browser to load this page void showDocument(URL u, String relative)

10 AudioClip Interface Once retrieved, an audio clip can be accessed in the following ways: void play() - play the clip straight through void loop() - play the clip over and over void stop() - stop the clip Note: Java only understands clips in AU form

11 Images Check out java.awt.image classes - lots of stuff Graphics methods for images: boolean drawImage(Image im, int x, int y, ImageObserver ob) - can use container for ob other args: im, x, y, int width, int height, ob im, x, y, Color bgColor, ob im, x, y, width, height, bgColor, ob im, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, ob d1,d2 and s1,s2 describe rectangles in the graphics window (destination) and image (source)

12 Image Class No ctor, created with getImage() from Applet or createImage() from Container methods: void flush() - reload before drawing again Graphics getGraphics() - only for image from createImage() int getHeight(ImageObserver ob) - may be -1 if not finished loading int getWidth(ImageObserver ob) - similar

13 Image Capabilities Animation through multiple images and threads Image processing (filters of various types, color processing, etc.) –check it out online


Download ppt "Chapter 12: Accessing the Web URL (Uniform Resource Locator) class Applet methods –for audio clips –for images –context interface."

Similar presentations


Ads by Google