Page 69 - การโปรแกรมคอมพิวเตอร์ขั้นสูง
P. 69

การ​เขียนโ​ปรแกรม​จาวาแ​ อพเพล็ต 12-59

ตาราง (ตอ่ )

SoundApplet.java

76 	          	   Object source = event.getSource();
77 	          	   if (source == playButton) {
78 	          	   	 onceClip = soundList.getClip(chosenFile);
79 	          	   	 onceClip.play();
80 	          	   	 stopButton.setEnabled(true);
81 	          	   	 showStatus("Playing sound " + chosenFile + ".");
82 	          	   	 if (onceClip == null) {
83 	          	   	 	 showStatus("Sound " + chosenFile + " not loaded yet.");
84 	          	   	}
85 	          	   	 return;
86 	          	   }
87
88 	          	   if (source == loopButton) {
89 	          	   	 loopClip = soundList.getClip(chosenFile);
90
91 	          	   	 looping = true;
92 	          	   	 loopClip.loop();
93 	          	   	 loopButton.setEnabled(false);
94 	          	   	 stopButton.setEnabled(true);
95 	          	   	 showStatus("Playing sound " + chosenFile + " continuously.");
96 	          	   	 if (loopClip == null) {
97 	          	   	 	 showStatus("Sound " + chosenFile + " not loaded yet.");
98 	          	   	}
99 	          	   	 return;
100 	         	   }
101
102 	         	   if (source == stopButton) {
103 	         	   	 if (looping) {
104 	         	   	 	 looping = false;
105 	         	   	 	 loopClip.stop();
106 	         	   	 	 loopButton.setEnabled(true);
107 	         	   }
108 	         	   else if (onceClip != null) {
109 	         	   	 onceClip.stop();
110 	         	   }
111 	         	   stopButton.setEnabled(false);
112 	         	   showStatus("Stopped playing " + chosenFile + ".");
   64   65   66   67   68   69   70   71   72   73   74