1 / 13

Chapter 12: Accessing the Web

Chapter 12: Accessing the Web. URL (Uniform Resource Locator) class Applet methods for audio clips for images context interface. 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)

wardah
Download Presentation

Chapter 12: Accessing the Web

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 <APPLET> tag can have params: <APPLET CODE = “MyApp.class” WIDTH = 500 HEIGHT = 300 <PARAM name = “NumPeople” value = “5”> <PARAM name = “Picture” value = “my.gif”> </APPLET> • 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

More Related