Java is a very popular programming language in the world today. It is made by Sun Microsystems, Inc., USA. It is a language that breaks through the user-side machine environment and CPU structure for Internet development, and writes once to execute on any machine (write Once,run Anywhere).
After describing the features and benefits of Java, I'll start by introducing how to make audio playback programs. There are many packages and classes in Java that can be used to make audio playback, including Java.applet.AudioClip, Com.sun.media.sound.JavaSoundAudioClip, and javax.sound.midi.spi& Javaw.sound.sampled.spi, where Java.applet.AudioClip is an interface from the JDK1.0, the rest of the classes are implemented for this interface and enrich its functionality.
Below, I will lead you to use the Javasoundaudioclip class in Com.sun.media.sound to make a simple audio player applet.
I am using the Borland Company's JBuilder, which is a large Java integrated development environment.
We create 4 classes, as shown in the following table:
Class name |
MyFrame |
Audioplay |
Gifpanel |
Test |
Function |
Interface GUI |
Play audio files |
A panel that holds GIF pictures |
Test class |
1. Generate Application GUI
First, use JBuilder's wizard to automatically generate a application with a menu bar, and then add controls to the frame. As shown below:
|
jlist |
jbutton |
jbutton |
jbutton |
jbutton |
jfilechooser |
name |
jbtnback |
jbtnstop |
jbtnforward |
filechooser |
feature |
playlist |
> back |
play |
stop |
forward |
Open file Dialog |
Add jlist below the button as a playlist, in order to avoid the monotony of the screen, we add a GIF on the right, in order to facilitate the management of GIF, we made a panel for it, forming a gifpanel class. The finished interface is shown in the following illustration: