Java Reference
In-Depth Information
/** Panel with a button to play/stop a clip in loop
*mode. **/
class AudioPanel extends JPanel implements ActionListener
{
AudioClip fAudioClip;
JButton fButton;
boolean fPlay = false;
/** Constructor gets the clip and makes a button for the
*panel. **/
AudioPanel (AudioClip audio - clip) {
fAudioClip = audio - clip;
fButton = new JButton ( " Play Clip " );
fButton.addActionListener (this);
add (fButton);
} // ctor
/** Button will start/stop the clip playing. **/
public void actionPerformed (ActionEvent e) {
if (fAudioClip! = null) {
if (!fPlay) {
fButton.setText ( " Stop clip " );
fAudioClip.loop ();
fPlay = true;
}
else {
fButton.setText ( " Play clip " );
fAudioClip.stop ();
fPlay = false;
}
}
} // actionPerformed
} // class AudioPanel
12.8 Performance and timing
Reducing the execution time in a Java program can be a very important part
of making it a useful tool, especially if the program must execute extensive
computations like those needed for a complicated mathematical algorithm or an
animation of a complex scene. There are various profiler tools available that give
detailed information on the time taken by various parts of a program, particularly
for method calls. The Sun J2SE java program, in fact, includes the options
-Xprof and -Xrunhprof to produce time profiles. We discuss here a more
basic but often effective approach. (See the Web Course Chapter 12 for more
information about profilers.)
 
Search WWH ::




Custom Search