Archive for August, 2007

Chapter 22 Java Media Framework and Java Sound (Web server)

Sunday, August 26th, 2007

Chapter 22 Java Media Framework and Java Sound (on CD) 1239 can play most JMF-supported media files with the possible exception of the latest versions of the formats. This application permits users to access files on the local computer that contain supported media types by clicking the Open File button. Clicking the Open Location button and specifying a media URL allows the user to access media from a media source, such as a capture device, a Web server, or a streaming source. A capture device (discussed in Section 22.3) reads media from audio and video devices such as microphones, CD players and cameras. A Real-Time Transport Protocol (RTP) stream is a stream of bytes sent over a network from a streaming server. An application buffers and plays the streaming media on the client computer. 1 // Fig. 22.1: SimplePlayer.java 2 // Opens and plays a media file from 3 // local computer, public URL, or an RTP session 4 5 // Java core packages 6 import java.awt.*; 7 import java.awt.event.*; 8 import java.io.*; 9 import java.net.*; 10 11 // Java extension packages 12 import javax.swing.*; 13 import javax.media.*; 14 15 public class SimplePlayer extends JFrame { 16 17 // Java media player 18 private Player player; 19 20 // visual content component 21 private Component visualMedia; 22 23 // controls component for media 24 private Component mediaControl; 25 26 // main container 27 private Container container; 28 29 // media file and media locations 30 private File mediaFile; 31 private URL fileURL; 32 33 // constructor for SimplePlayer 34 public SimplePlayer() 35 { 36 super( “Simple Java Media Player” ); 37 38 container = getContentPane(); 39 40 // panel containing buttons 41 JPanel buttonPanel = new JPanel(); Fig. 22.1 Playing media with interface Player(part 1 of 8) .
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

Web design - 1238 Java Media Framework and Java Sound (on

Sunday, August 26th, 2007

1238 Java Media Framework and Java Sound (on CD) Chapter 22 In addition to the sample media clips provided with this chapter s examples on the CD, many Web sites offer an abundant supply of free-for-download audio and video clips. You can download media clips from these sites (and many others on the Internet) and use them to test the examples in this chapter. We present a list of sites here to get you started. Free Audio Clips (www.freeaudioclips.com) is an excellent site for various types of audio files. The 13 Even site (www.13-even.com/media.html) provides audio and video clips in many formats for your personal use. If you are looking for MIDI audio files for use in Section 22.7, check out the free MIDI clips at www.freestuffgalore.commidi.asp. Funny Video Clips (www.video-clips.co.uk) offers entertaining material. Microsoft s downloads site (msdn.microsoft.com/downloads) contains a multimedia section providing audio clips and other media. Currently, JMF is available as an extension package separate from the Java 2 Software Development Kit. The CD that accompanies this book contains JMF 2.1.1. The most recent JMF implementation can be downloaded from the official JMF Web site: java.sun.com/products/java-media/jmf The JMF Web site provides versions of the JMF that take advantage of the performance features of the platform on which the JMF is running. For example, the JMF Windows Performance Pack provides extensive media and device support for Java programs running on Microsoft Windows platforms (Windows 95/98/NT 4.0/2000). JMF s official Web site also provides continually updated support, information and resources for JMF programmers. Portability Tip 22.1 Writing programs using JMF s Windows Performance Pack reduces the portability of those programs to other operating systems. The rest of this chapter discusses the Java Sound API and its extensive sound-processing capabilities. Internally, the JMF uses Java Sound for its audio functions. In Sections 22.5 through 22.7, we will demonstrate sampled audio playback and MIDI functionalities using Java Sound, a standard extension of the Java 2 Software Development Kit. 22.2 Playing Media The JMF is commonly used to playback media clips in Java applications. Many applications such as financial managers, encyclopedias and games use multimedia to illustrate application features, present educational content and entertain users. The JMF offers several mechanisms for playing media, the simplest of which is via objects that implement interface Player. Interface Player (package javax.media) extends Controller, which is a handler for JMF-supported media. The following steps are needed to play a media clip: 1. Specify the media source. 2. Create a Player for the media. 3. Obtain the output media and Player controls. 4. Display the media and controls. Class SimplePlayer (Fig. 22.1) is a simple Java media player program that demonstrates several common features of popular media players. The SimplePlayer demo
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

Photography web hosting - Chapter 22 Java Media Framework and Java Sound

Saturday, August 25th, 2007

Chapter 22 Java Media Framework and Java Sound (on CD) 1237 Outline 22.1 Introduction 22.2 Playing Media 22.3 Formatting and Saving Captured Media 22.4 RTP Streaming 22.5 Java Sound 22.6 Playing Sampled Audio 22.7 Musical Instrument Digital Interface (MIDI) 22.7.1 MIDI Playback 22.7.2 MIDI Recording 22.7.3 MIDI Synthesis 22.8 Internet and World Wide Web Resources 22.9 (Optional Case Study) Thinking About Objects: Animation and Sound in the View Summary Terminology Self-Review Exercises Answers to Self-Review Exercises Exercises 22.1 Introduction This chapter continues our multimedia discussions of Chapter 18 by introducing some of Java s multimedia APIs that enable programmers to enhance applications with video and audio features. In recent years, the digital multimedia sector of the computer industry has experienced tremendous growth, as evidenced by the enormous quantity of multimedia content available on the Internet. Web sites have been transformed from text-based HTML pages to multimedia-intensive experiences. Advances in hardware and software technologies have allowed developers to integrate multimedia into the simplest applications. At the high end of multimedia applications, the video game industry has used multimedia programming to take advantage of the latest hardware technologies, such as 3D video cards that create virtual reality experiences for users. Acknowledging that Java applications should support digital video and audio capabilities, Sun Microsystems, Intel and Silicon Graphics worked together to produce a multimedia API known as the Java Media Framework (JMF). The JMF API is one of several multimedia APIs in Java. Using the JMF API, programmers can create Java applications that play, edit, stream and capture many popular media types. The first half of this chapter discusses the JMF API. IBM and Sun developed the latest JMF specification version 2.0. Sun provides a reference implementation JMF 2.1.1 of the JMF specification which supports media file types such as Microsoft Audio/Video Interleave (.avi), Macromedia Flash 2 movies (.swf), Future Splash (.spl), MPEG Layer 3 Audio (.mp3), Musical Instrument Digital Interface (MIDI;.mid), MPEG-1 videos (.mpeg, .mpg), QuickTime (.mov), Sun Audio (.au), Wave audio (.wav), AIFF (.aiff) and GSM (.gsm) files. The JMF also supports media from capture devices such as microphones and digital cameras.
You want to have a cheap webhost for your apache application, then check apache web hosting services.

22 Java Media Framework and Java Sound (on (Business web site)

Saturday, August 25th, 2007

22 Java Media Framework and Java Sound (on CD) Objectives To understand the capabilities of the Java Media Framework (JMF). To understand the capabilities of the Java Sound API. To be able to play audio and video media with JMF. To be able to stream media over a network. To be able to capture, format and save media. To be able to play sounds with the Java Sound API. To be able to play, record, and synthesize MIDI with the Java Sound API. TV gives everyone an image, but radio gives birth to a million images in a million brains. Peggy Noonan Noise proves nothing. Often a hen who has merely laid an egg cackles as if she had laid an asteroid. Mark Twain, Following the Equator A wide screen just makes a bad film twice as bad. Samuel Goldwyn Isn t life a series of images that change as they repeat themselves? Andy Warhol
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

Chapter 21 Collections 1235 21.6 State (Web design software) whether each

Friday, August 24th, 2007

Chapter 21 Collections 1235 21.6 State whether each of the following is true or false. If false, explain why. a) Elements in a Collection must be sorted in ascending order before performing a binarySearch. b) Method first gets the first element in a TreeSet. c) A List created with Arrays.asList is resizable. d) Class Arrays provides static method sort for sorting array elements. 21.7 Rewrite method printList of Fig. 21.4 to use a ListIterator. 21.8 Rewrite lines 16 23 in Fig. 21.4 to be more concise by using the asList method and the LinkedList constructor that takes a Collection argument. 21.9 Write a program that reads in a series of first names and stores them in a LinkedList. Do not store duplicate names. Allow the user to search for a first name. 21.10 Modify the program of Fig. 21.13 to count the number of occurrences of all letters (e.g., five occurrences of “o” in the example). Display the results. 21.11 Write a program that determines and prints the number of duplicate words in a sentence. Treat uppercase and lowercase letters the same. Ignore punctuation. 21.12 Rewrite your solution to Exercise 19.8 to use a LinkedList collection. 21.13 Rewrite your solution to Exercise 19.9 to use a LinkedList collection. 21.14 Write a program that takes a whole-number input from a user and determines if it is prime. If the number is prime, add it to a JTextArea. If the number is not prime, display the prime factors of the number in a JLabel. Remember that a prime number s factors are only 1 and the prime number itself. Every number that is not prime has a unique prime factorization. For example, consider the number 54. The factors of 54 are 2, 3, 3 and 3. When the values are multiplied together, the result is 54. For the number 54, the prime factors output should be 2 and 3. Use Sets as part of your solution. 21.15 Rewrite your solution to Exercise 22.21 to use a LinkedList. 21.16 Write a program that tokenizes (using class StreamTokenizer) a line of text input by the user and places each token in a tree. Print the elements of the sorted tree. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/12/01
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

1234 Collections Chapter 21 sortalgorithm TreeSet class SortedMap

Friday, August 24th, 2007

1234 Collections Chapter 21 sortalgorithm TreeSet class SortedMap collection interface unmodifiable collections SortedSet collection interface Vector class stable sort view synchronization wrappers view an array as a List TreeMap class wrapper class SELF-REVIEW EXERCISES 21.1 Fill in the blanks in each of the following statements: a) Objects in a collection are called . b) An element in a List can be accessed by using the element s . c) Lists are sometimes called . d) You can use a/an to create a collection that offers only read-only access to others while allowing read write access to yourself. e) can be used to create stacks, queues, trees and deques (double-ended queues). 21.2 State whether each of the following is true or false. If false, explain why. a) A Set can contain duplicates. b) A Map can contain duplicate keys. c) A LinkedList can contain duplicates. d) Collections is an interface. e) Iterators can remove elements, while Enumerations cannot. ANSWERS TO SELF-REVIEW EXERCISES 21.1 a) elements. b) index. c) sequences. d) unmodifiable wrapper. e) LinkedLists. 21.2 a) False. A Set cannot contain duplicate values. b) False. A Map cannot contain duplicate keys. c) True. d) False. Collections is a class, and Collection is an interface. e) True. EXERCISES 21.3 Define each of the following terms: a) Collection b) Collections c) Comparator d) List 21.4 Briefly answer the following questions: a) What is the primary difference between a Setand a Map? b) Can a double-subscripted array be passed to Arrays method asList? If yes, how would an individual element be accessed? c) What must you do before adding a primitive data type (e.g., double) to a collection? 21.5 Explain briefly the operation of each of the following Iterator-related methods: a) iterator b) hasNext c) next Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/12/01
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

Web hosting directory - Chapter 21 Collections 1233 TreeMap implement the Map

Thursday, August 23rd, 2007

Chapter 21 Collections 1233 TreeMap implement the Map interface. HashMaps store elements in a HashTable, and TreeMaps store elements in a tree. Interface SortedMap extends Map and maintains its elements in sorted order. Class TreeMap implements SortedMap. The built-in collections are unsynchronized. Concurrent access to a Collection by independent threads could cause indeterminate results. To prevent this, synchronization wrappers are used around classes that might be accessed by multiple threads. The Collections API provides a set of publicstatic methods for converting collections to unmodifiable versions. Unmodifiable wrappers throw UnsupportedOperation- Exceptions if attempts are made to modify the collection. The collections framework provides various abstract implementations (i.e., bare bones implementations of collection interfaces from which the programmer can quickly flesh out complete customized implementations). TERMINOLOGY AbstractCollection class hasNext method AbstractList class implementation classes AbstractMapclass insert an element into a collection AbstractSequentialList class interface AbstractSet class isEmpty method add method iterator addFirstmethod Iterator interface addLast method key algorithms lexicographical comparison ArrayList LinkedList class arrays List interface arrays as collections ListIterator Arrays.asList map bidirectional iterator Map collection interface binarySearch algorithm mapping keys to values clearmethod mappings Collection interface maps as collections collections max algorithm Collections class min algorithm collections framework modifiable collections collections placed in arrays natural ordering Comparator object nextmethod copy algorithm one-to-one mapping data structures ordered collection delete an element from a collection ordering deque queue double-ended queue (deque) range-view methods duplicate elements reverse algorithm Enumeration interface reverseOrdermethod fill algorithm sequence HashMap class Set interface HashSet class shuffle algorithm Hashtable class sizemethod hashtable implementation sort a List Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/12/01
Check Tomcat Web Hosting services for best quality webspace to host your web application.

1232 Collections Chapter 21 Class Arrays (Best web hosting) provides method

Thursday, August 23rd, 2007

1232 Collections Chapter 21 Class Arrays provides method asList for getting a Listview of the array. A Listview allows the programmer to programmatically manipulate the array as if it were a List. This allows the programmer to treat an array as a collection. Any modifications made through the Listview change the array, and any modifications to the array change the List view. Method size gets the number of items in a List, and method get gets an individual List element. Interface Collection is the root interface in the collections hierarchy from which interfaces Setand List are derived. Interface Collection contains bulk operations for adding, clearing, comparing and retaining objects in the collection. Interface Collection provides a method iterator for getting an Iterator. Class Collections provides static methods for manipulating collections. Many of the methods are implementations of polymorphic algorithms for searching, sorting and so on. A List is an ordered Collection that can contain duplicate elements. A List is sometimes called a sequence. Interface List is implemented by classes ArrayList, LinkedListand Vector. Class ArrayList is a resizable-array implementation of a List. ArrayList behavior and capabilities are similar to those of class Vector. A LinkedList is a linked-list implementation of a List. Iterator method hasNext determines whether a Collection contains another element. Method hasNext returns true if another element exists, false otherwise. Method next returns the next object in the Collection and advances the Iterator. Method subList gets a portion of a List, called a sublist. Any changes made to a sublist are also made to the List (i.e., the sublist is a list view of its corresponding List elements). Method clear removes elements from a List. Method toArray returns the contents of a collection as an array. Algorithms sort, binarySearch, reverse, shuffle, filland copy operate on Lists. Algorithms min and max operate on Collections. Algorithm reverse reverses the elements of a List, fill sets every List element to a specified Object and copy copies elements from one List into another List. Algorithm sort sorts the elements of a List. Algorithms min and max find the smallest item and the largest item in a Collection. The Comparator object provides a means of sorting a Collection s elements in an order other than the Collection s natural order. Method reverseOrder returns a Comparator object that represents the reverse order for a collection. Algorithm shufflerandomly orders the elements of a List. Algorithm binarySearch locates an Object in a List. A Set is a Collection that contains no duplicate elements. The collections framework contains two Set implementations: HashSet and TreeSet. HashSet stores its elements in a hash table; TreeSetstores its elements in a tree. Interface SortedSet extends Set and maintains its elements in sorted order. Class TreeSet implements SortedSet. Method headSetgets a subset of a TreeSet less than a specified element. Any changes made to the subset are made to the TreeSet. Method tailSet gets a subset greater than or equal to a specified element. Any changes made through the tailSet view are made to the TreeSet. Maps map keys to values and cannot contain duplicate keys. Maps differ from Sets in that Maps contain both keys and the values, whereas Sets contain only keys. Classes HashMap and Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/12/01
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.

Chapter 21 Collections 1231 Of the 23 design (Web hosting directory)

Wednesday, August 22nd, 2007

Chapter 21 Collections 1231 Of the 23 design patterns, we discussed 18 of the more popular ones used by the Java community. In Sections 9.24, 13.18, 15.13, 17.11 and 21.12, we divided the discussion according to how certain Java packages such as package java.awt, javax.swing, java.io, java.net and java.util use these design patterns. We also discussed patterns not described by the gang of four, such as concurrency patterns, which are useful in multithreaded systems, and architectural patterns, which help designers assign functionality to various subsystems in a system. We have motivated each pattern that is, explained why that pattern is important and how it may be used. When appropriate, we supplied several examples in the form of real-world analogies (e.g., the adapter in the Adapter design pattern is similar to an adapter for a plug on an electrical device). We also gave examples of how Java packages take advantage of design patterns (e.g., Swing GUI components use the Observer design pattern to collaborate with their listeners to respond to user interactions). We also provided examples of how certain programs in Java How to Program, Fourth edition used design patterns (e.g., the elevator-simulation case study in our optional Thinking About Objects sections uses the State design pattern to represent a Person object s location in the simulation). We hope that you view our Discovering Design Patterns sections as a beginning to further study of design patterns. If you have not done so already, we recommend that you visit the many URLs we have provided in Section 9.24.5, Internet and World-Wide-Web Resources. We recommend that you then read the gang-of-four book. This information will help you build better systems using the collective wisdom of the object-technology industry. If you have studied the optional sections in this book, you have been introduced to more substantial Java systems. If you have read our optional Thinking About Objects Sections, you have immersed yourself in a substantial design and Java implementation experience learning a disciplined approach to object-oriented design with the UML. If you have read our optional Discovering Design Patterns Sections, you have raised your awareness of the more advanced topic of design patterns. We hope you continue your study of design patterns, and we would be most grateful if you would send your comments, criticisms and suggestions for improvement of Java How to Program to deitel@deitel.com. Good luck! SUMMARY The Java collections framework gives the programmer access to prepackaged data structures, as well as algorithms for manipulating those data structures. Java 2 provides an entire collections framework, whereas earlier versions of Java provided just a few collection classes, like HashTableand Vector, as well as built-in array capabilities. A collection is a data structure; actually, it is an object that can hold other objects. The collection interfaces define the operations that can be performed on each type of collection. The collections framework includes a number of other features that minimize the amount of work programmers need to do to create and manipulate collections. This structure is an effective implementation of the notion of reuse. The classes and interfaces that compose the collections framework are members of the java.util package. Class Arrays provides static methods for manipulating arrays. Class Arrays methods include binarySearch for searching a sorted array, equals for comparing arrays, fill for placing items in an array, sort for sorting an array and asList. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/12/01
We recommend high quality webhost to host and run your jsp application: christian web host services.

1230 Collections Chapter (Starting a web site) 21 es MyLine, MyOval and

Tuesday, August 21st, 2007

1230 Collections Chapter 21 es MyLine, MyOval and MyRect represent shape classes that extend abstract superclass MyShape. We could modify this exercise to allow the user to create, copy and paste new instances of class MyLine into the program. The Prototype design pattern allows an object called a prototype to return a copy of that prototype to a requesting object called a client. Every prototype must belong to a class that implements a common interface that allows the prototype to clone itself. For example, the Java API provides method clone from class java.lang.Object and interface java.lang.Cloneable any object from a class implementing Cloneable can use method cloneto copy itself. Specifically, method clone creates a copy of an object, then returns a reference to that object. If we designate class MyLineas the prototype for Exercise 9.28, then class MyLine must implement interface Cloneable. To create a new line in our drawing, we clone the MyLineprototype. To copy a preexisting line, we clone that object. Method clone also is useful in methods that return a reference to an object, but the developer does not want that object to be altered through that reference method clonereturns a reference to the copy of the object instead of returning that object s reference. For more information of interface Cloneable, visit www.java.sun.com/j2se/1.3/docs/api/java/lang/Cloneable.html 21.12.2 Behavioral Design Patterns We conclude the discussion of behavioral design patterns by discussing the Iterator design pattern. Iterator Designers use data structures such as arrays, linked lists and hash tables, to organize data in a program. The Iterator design pattern allows objects to access individual objects from any data structure without knowing the data structure s behavior (such as traversing the structure or removing an element from that structure) or how that data structure stores objects. Instructions for traversing the data structure and accessing its elements are stored in a separate object called an iterator. Each data structure can create an iterator each iterator implements methods of a common interface to traverse the data structure and access its data. An object can traverse two differently structured data structures such as a linked list and a hash table in the same manner, because both data structures contain an iterator object that belongs to a class implementing a common interface. Java provides interface Iterator from package java.util, which we discussed in Section 21.5 class CollectionTest (Fig 21.3) uses an Iterator object. 21.12.3 Conclusion In our optional Discovering Design Patterns sections, we have introduced the importance, usefulness and prevalence of design patterns. We have mentioned that in their book Design Patterns, Elements of Reusable Object-Oriented Software, the gang of four described 23 design patterns that provide proven strategies for building systems. Each pattern belongs to one of three pattern categories: creational, which address issues related to object creation; structural, which provide ways to organize classes and objects in a system; and behavioral, which offer strategies to model how objects collaborate with one another in a system. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/12/01
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.