Page 67 - การโปรแกรมคอมพิวเตอร์ขั้นสูง
P. 67
การเขียนโปรแกรมจ าวาแ อพเพล็ต 12-57
SoundApplet.java
1 import javax.swing.*;
2 import java.applet.*;
3 import java.awt.*;
4 import java.awt.event.*;
5
6 public class SoundApplet extends JApplet
7 implements ActionListener, ItemListener {
8 AppletSoundList soundList;
9 String auFile = "spacemusic.au";
10 String aiffFile = "flute+hrn+mrmba.aif";
11 String midiFile = "trippygaia1.mid";
12 String rmfFile = "jungle.rmf";
13 String wavFile = "bottle-open.wav";
14 String chosenFile;
15 AudioClip onceClip, loopClip;
16
17 JComboBox formats;
18 JButton playButton, loopButton, stopButton;
19 boolean looping = false;
20
21 public void init() {
22 String [] fileTypes = {auFile, aiffFile, midiFile, rmfFile, wavFile};
23 formats = new JComboBox(fileTypes);
24 formats.setSelectedIndex(0);
25 chosenFile = (String) formats.getSelectedItem();
26 formats.addItemListener(this);
27
28 playButton = new JButton("Play");
29 playButton.addActionListener(this);
30
31 loopButton = new JButton("Loop");
32 loopButton.addActionListener(this);
33
34 stopButton = new JButton("Stop");
35 stopButton.addActionListener(this);
36 stopButton.setEnabled(false);
37
38 JPanel controlPanel = new JPanel();