Playing sounds
- The player piano
The player piano applet plays sound clips
Example 6 PushButton
Music (Lalani, Jamsa: Java Programmers Library)
Sound clips must be stored in a file in .au format.
The basic structure of a playing application is to
-
Make a variable for the audio clip. (The class AudioClip)
-
AudioClip clip;
-
Load the audioclip
-
clip = getAudioClip(getCodeBase(), "file.au");
-
Play the clip once, loop is or stop it
-
clip.loop();
clip.play();
clip.stop();
See the playing
sound - page in the Tutorial
Doing animations
The
animation page in Java Tutorial
The two basic techniques for simple animation are :
-
drawing graphic elements on screen and repeating it with suitable delays.
-
Preparing a series of images and displaying them with suitable delays to
get the desired effect.
Drawing graphic animations
The
graphics animation page in the tutorial
The page presents the basic animation loop technique and shows how to
avoid flickering in the image.
Moving image
The animation can be created moving an image on the screen.
This is demionstrated on the Moving
image page
Repeating series of images
The Duke - animation is a well known icon of Java. Here you learn how to
produce animations like that.
The
animation page of the Tutorial
For advanceds animation Sun has created an "Animator"
which can be used as an applet using the parameters of the animator-applet.
You can move the image, attach sound to it change the timing et c.