{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture26-applets

lecture26-applets - Lecture 26 Applets(conclusion Lecture...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture 26: Applets (conclusion) CS 170, Section 000 8 December 2009 12/3/2009 CS170, Section 000, Fall 2009 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Lecture Plan ¾ Java audio, graphics Homework 9 (extra credit): Due Friday, Dec 18 Homework 9 (extra credit): Due Friday, Fi l C t t L i ti Final Content, Logistics Course evaluations CS170, Section 000, Fall 2009 2
Background image of page 2
Some Nice Examples of HW8 Dustin Goodman: http://www.mathcs.emory.edu/~dgoodm2/hw8.html 12/8/2009 CS170, Section 000, Fall 2009 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Locating Resource Using the URL Class ¾ The java.net.URL class can be used to identify files (image, audio, text, etc.) on the Internet. ¾ URL (Uniform Resource Locator) is a pointer to a URL (Uniform Resource Locator) is a pointer to a “resource” on the World Wide Web on a local machine or a remote host. ¾ A resource can be something as simple as a file or a directory. 4
Background image of page 4
Creating a URL from a Class Reference java.lang.Class metaObject = this .getClass(); The Class class provides access to useful information about the class, such as the data fields, constructors, and methods. It also contains the getResource(filename) method, which can be used to obtain the URL of a given file name in the class directory. T bt i th URL f fil i th l di t To obtain the URL of a file in the class directory, use URL url = metaObject.getResource(filename); For example suppose the class directory is c:\book the following statements create a URL for For example, suppose the class directory is c:\book , the following statements create a URL for c:\book\image\us.gif . Class metaObject = this .getClass(); URL url = metaObject.getResource("image/us.gif"); You can now create an ImageIcon using ImageIcon imageIcon = new ImageIcon(url); 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
“Bonus” Material: Java Audio ¾ To play an audio file in an applet, first create an audio clip object for the audio file the audio file. ¾ use the static method newAudioClip() in the java.applet.Applet class: AudioClip audioClip = Applet.newAudioClip(url); AudioClip audioClip Applet.newAudioClip(url); Audio was originally used with Java applets. For this reason, the AudioClip interface is in the java.applet package. The following statements, for example, create an AudioClip for the beep.au audio file in the same directory with the class you are running. Class class = this.getClass(); URL url = class.getResource("beep.au"); AudioClip audioClip = Applet.newAudioClip(url); 12/8/2009 CS170, Section 000, Fall 2009 6
Background image of page 6