lecture26-applets

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

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

View Full Document Right Arrow Icon
cture 6: Applets (conclusion) Lecture 26: Applets (conclusion) CS 170, Section 000 ecember 2009 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 DocumentRight Arrow Icon
Lecture Plan ¾ Java audio, graphics ± omework (extra credit): Due Friday, ec 18 Homework 9 (extra credit): Due Friday, Dec 18 ± 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 DocumentRight 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. RL niform 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. 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); r example suppose the class directory is ook 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 DocumentRight Arrow Icon
“Bonus” Material: Java Audio ¾ To play an audio file in an applet, first create an audio clip object for e audio file the audio file. ¾ use the static method newAudioClip() in the java.applet.Applet class: udioClip udioClip = pplet.newAudioClip rl AudioClip audioClip Applet.newAudioClip(url); Audio was originally used with Java applets. For this reason, the AudioClip interface is in the va.applet ackage. ud oC p te ace s t e ja a app et pac age The following statements, for example, create an AudioClip for the eep.au audio file in the same directory with the class you are running. 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
Playing Audio «interface» l t A d i C l i java.applet.AudioClip +play() Starts playing this audio clip. Each time this method is called, the clip is restarted from the beginning.
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/03/2010 for the course CS CS 170 taught by Professor Eugeneagichtein during the Fall '09 term at Emory.

Page1 / 26

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

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online