Validated by Amaya

Richard G Baldwin (512) 223-4758, NRG Room 4238, Baldwin@DickBaldwin.com, http://www.austincc.edu/baldwin

INEW 2338 Advanced Java Programming

Assignment 6 - Multimedia - Chapter 8

Revised 08/17/13

The files that you deliver for this assignment must include a controlling class file named Asg06.class plus all of the source code files that you compiled to produce your class files.

Click here for general requirements regarding all programming assignments.

Click here to download a zip file containing a sample version of this assignment.  Your application must replicate the look, feel, and behavior of this sample except that your name must be included in the output of your version of the application where indicated.  In addition, the zip file contains an audio file that you will need to complete this assignment.

Before starting to write this assignment, you should study the study guide entitled Multimedia.

Write a Java application that uses the Java sound API, along with Swing, to simulate a simple kitchen timer.

As shown in Figure 1, the program places a JFrame on the screen with a width of 200 pixels and a height of 100 pixels.  The JFrame contains a JLabel and a JTextField.  Your name must appear in the banner at the top of the frame.


Figure 1 Program GUI

When you type a value into the text field and press the Enter key, the timer starts running.  When a time interval equal to the time shown in in the text field (seconds) has passed, the program begins sounding a repetitive audio alarm.  The audio alarm uses an audio file named Asg06.au.  You will find that audio file in the downloadable zip file discussed above.

The program loops and repetitively plays the sound file until the user presses the X button in the upper right of the frame.  Then the program terminates.  The program inserts a time delay of approximately five seconds between each successive playback of the audio file.

Additional comments
Writing Java programs to play sound files can often be tricky due to many factors that are beyond the immediate control of the programmer, such the type of sound card installed in the computer, the audio drivers that are installed, etc.

For example, when I originally wrote the program for this assignment in the Fall of 2004 and tested it on my HP laptop computer using the sound file named Asg06.au, everything worked just fine.

Because of problems that I encountered installing Service Pack 2 for WinXP in December of 2004, it was necessary for me to completely rebuild the OS on my laptop.  At that time, I also upgraded Java on my laptop from version 1.4.2 to version 1.5.  Following that, my version of this program would not successfully play the file named Asg06.au on my laptop, but it would successfully play other files of type .au.

Be aware that two audio files of the same type can contain data that is formatted in different ways.  For example, one common format that is used in files of type .au is:

PCM_SIGNED 11025.0 Hz, 8 bit, mono, 1 bytes/frame

This is the data format in the file named Asg06.au.

Another common data format that is used in files of type .au is:

PCM_SIGNED 8000.0 Hz, 16 bit, mono, 2 bytes/frame, big-endian

During the period that I was having difficulty playing the file named Asg06.au, I determined that my version of this program would play files in the second format listed above on my laptop, but would not play files in the first format listed above.  During that same period, however, my version of the program would play files in either format on the computers in the ACC lab on the Northridge campus.  Those computers were also running WinXP with service pack 2 installed.  They were also running Java version 1.5.

In April of 2005, I received a notification from Sun that I needed to download and install an updated version of the JRE for 5.0, which I did.  (Apparently when I installed 5.0 back in December, I installed some sort of automatic notification feature.)  Following that, I discovered that the update seemed to have cured all of the problems that I was having with the program for Asg #6.  Following the update, I was able to execute that program from the original zip file using the original sound file named Asg06.au with no difficulty whatsoever.

Here is what was installed on my computer following the update:

C:\jnk>java -version
java version "1.5.0_02>
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode, sharing)

If you haven't updated to this level yet, you may want to do so.  Apparently the update included some bug fixes.

I have no explanation for this behavior other than a guess that I was missing a critical driver on my laptop.

Why am I telling you this?
Because it may turn out that my version of the program won't successfully play the audio file named Asg06.au on your computer.  If that is the case, you should deal with that issue before attempting to write your own version of the program to play that particular audio file.

If you are unable to play that specific audio file on your system, I recommend that you do the following.  First make certain that your operating system and your Java installation are completely up to date.  Then go to the following URL and download the program named AudioPlayer02 that is available in lesson number 2016 entitled Java Sound, Playing Back Audio Files using Java.

http://www.developer.com/java/other/article.php/2173111

Do a Google search and download a selection of audio files of type .au from the web.  Use the program named AudioPlayer02 to identify a particular short audio file of type .au that can be successfully played on your computer.  (That program will also display the format of the audio file that you are attempting to play.)  You might also consider creating your own audio file using the program named AudioRecorder02 in the lesson entitled Java Sound, Capturing Microphone Data into an Audio File that you will find at the following URL:

http://www.developer.com/java/other/article.php/2105421

Once you have identified an audio file that is compatible with Java programming on your computer, rename it Asg06.au.  Use that file to develop your version of this program.

Encapsulate that audio file in the zip file that you submit for this assignment along with your source code and class files. Also send an email message notifying me that you have included a special audio file for use with your program.  When I test your program, I will test it using your audio file in place of the one that I delivered to you with this assignment.  If that doesn't work, I will test your program with the original audio file named Asg06.au that I provided to you.  Hopefully one of them will work with your program on the computers in the ACC lab at the Northridge campus.

-end-

File:  Asg06.htm