<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta name="generator" content="pdf2htmlEX">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="stylesheet" href="https://static.pudn.com/base/css/base.min.css">
<link rel="stylesheet" href="https://static.pudn.com/base/css/fancy.min.css">
<link rel="stylesheet" href="https://static.pudn.com/prod/directory_preview_static/626ff1b640256a40ceb02a0b/raw.css">
<script src="https://static.pudn.com/base/js/compatibility.min.js"></script>
<script src="https://static.pudn.com/base/js/pdf2htmlEX.min.js"></script>
<script>
try{
pdf2htmlEX.defaultViewer = new pdf2htmlEX.Viewer({});
}catch(e){}
</script>
<title></title>
</head>
<body>
<div id="sidebar" style="display: none">
<div id="outline">
</div>
</div>
<div id="pf1" class="pf w0 h0" data-page-no="1"><div class="pc pc1 w0 h0"><img class="bi x0 y0 w1 h1" alt="" src="https://static.pudn.com/prod/directory_preview_static/626ff1b640256a40ceb02a0b/bg1.jpg"><div class="c x0 y1 w2 h2"><div class="t m0 x1 h3 y2 ff1 fs0 fc0 sc0 ls0 ws0">第<span class="_ _0"> </span><span class="ff2 sc1">13<span class="_ _0"> </span></span>章<span class="ff2 sc1"> <span class="ff3 fs1">Java Applet</span></span></div><div class="t m0 x1 h4 y3 ff1 fs2 fc0 sc0 ls0 ws0">实验<span class="_ _1"> </span><span class="ff4 sc1">1 </span>播放音频</div><div class="t m0 x1 h5 y4 ff2 fs3 fc0 sc1 ls0 ws0">1<span class="ff1 sc0">.答案:</span></div><div class="t m0 x1 h6 y5 ff1 fs4 fc0 sc1 ls0 ws0">【代码<span class="_ _2"> </span><span class="ff3">1</span>】:<span class="_ _0"> </span><span class="ff3"> <span class="fs3">clip.stop();</span></span></div><div class="t m0 x1 h6 y6 ff1 fs4 fc0 sc1 ls0 ws0">【代码<span class="_ _2"> </span><span class="ff3">2</span>】:<span class="_ _0"> </span><span class="ff3"> <span class="fs3">clip.play();</span></span></div><div class="t m0 x1 h6 y7 ff1 fs4 fc0 sc1 ls0 ws0">【代码<span class="_ _2"> </span><span class="ff3">3</span>】:<span class="_ _0"> </span><span class="ff3"> <span class="fs3">clip.loop();</span></span></div><div class="t m0 x1 h6 y8 ff1 fs4 fc0 sc1 ls0 ws0">【代码<span class="_ _2"> </span><span class="ff3">4</span>】:<span class="_ _0"> </span><span class="ff3"> <span class="fs3">clip.stop();</span></span></div><div class="t m0 x1 h5 y9 ff2 fs3 fc0 sc1 ls0 ws0">2<span class="ff1 sc0">.模板代码</span><span class="fs4"> </span></div><div class="t m0 x2 h7 ya ff2 fs3 fc0 sc1 ls0 ws0">PlayAudioClip.java</div><div class="t m0 x3 h8 yb ff3 fs4 fc0 sc1 ls0 ws0">import java.applet.*;</div><div class="t m0 x3 h8 yc ff3 fs4 fc0 sc1 ls0 ws0">import java.awt.*;</div><div class="t m0 x3 h8 yd ff3 fs4 fc0 sc1 ls0 ws0">import java.awt.event.*;</div><div class="t m0 x3 h8 ye ff3 fs4 fc0 sc1 ls0 ws0">public class PlayAudioClip extends <span class="_ _3"></span>Applet implements <span class="_ _3"></span>ActionListener<span class="_ _3"></span>,Runnable,ItemListener { </div><div class="t m0 x3 h8 yf ff3 fs4 fc0 sc1 ls0 ws0"> AudioClip clip;</div><div class="t m0 x3 h8 y10 ff3 fs4 fc0 sc1 ls0 ws0"> Choice choice;</div><div class="t m0 x3 h8 y11 ff3 fs4 fc0 sc1 ls0 ws0"> T<span class="_ _3"></span>extField text;</div><div class="t m0 x3 h8 y12 ff3 fs4 fc0 sc1 ls0 ws0"> Thread thread;</div><div class="t m0 x3 h8 y13 ff3 fs4 fc0 sc1 ls0 ws0"> String item=null;</div><div class="t m0 x3 h8 y14 ff3 fs4 fc0 sc1 ls0 ws0"> Button button_play<span class="_ _3"></span>,button_loop,button_stop;</div><div class="t m0 x3 h8 y15 ff3 fs4 fc0 sc1 ls0 ws0"> public void init() { </div><div class="t m0 x3 h8 y16 ff3 fs4 fc0 sc1 ls0 ws0"> choice=new Choice();</div><div class="t m0 x3 h8 y17 ff3 fs4 fc0 sc1 ls0 ws0"> thread=new Thread(this); </div><div class="t m0 x3 h6 y18 ff3 fs4 fc0 sc1 ls0 ws0"> int N=Integer<span class="_ _3"></span>.parseInt(getParameter("<span class="ff1">总数</span>"));</div><div class="t m0 x3 h8 y19 ff3 fs4 fc0 sc1 ls0 ws0"> for(int i=1;i<=N;i++)</div><div class="t m0 x3 h8 y1a ff3 fs4 fc0 sc1 ls0 ws0"> choice.add(getParameter(String.valueOf(i))); </div><div class="t m0 x3 h6 y1b ff3 fs4 fc0 sc1 ls0 ws0"> button_play=new Button("<span class="ff1">开始播放</span>"); </div><div class="t m0 x3 h6 y1c ff3 fs4 fc0 sc1 ls0 ws0"> button_loop=new Button("<span class="ff1">循环播放</span>");</div><div class="t m0 x3 h6 y1d ff3 fs4 fc0 sc1 ls0 ws0"> button_stop=new Button("<span class="ff1">停止播放</span>"); </div><div class="t m0 x3 h8 y1e ff3 fs4 fc0 sc1 ls0 ws0"> text=new T<span class="_ _4"></span>extField(12);</div><div class="t m0 x3 h8 y1f ff3 fs4 fc0 sc1 ls0 ws0"> button_play<span class="_ _4"></span>.addActionListener(this); </div><div class="t m0 x3 h8 y20 ff3 fs4 fc0 sc1 ls0 ws0"> button_stop.addActionListener(this);</div><div class="t m0 x3 h8 y21 ff3 fs4 fc0 sc1 ls0 ws0"> button_loop.addActionListener(this); </div><div class="t m0 x3 h8 y22 ff3 fs4 fc0 sc1 ls0 ws0"> choice.addItemListener(this);</div><div class="t m0 x3 h8 y23 ff3 fs4 fc0 sc1 ls0 ws0"> add(choice);</div><div class="t m0 x3 h8 y24 ff3 fs4 fc0 sc1 ls0 ws0"> add(button_play);</div><div class="t m0 x3 h8 y25 ff3 fs4 fc0 sc1 ls0 ws0"> add(button_loop);</div><div class="t m0 x3 h8 y26 ff3 fs4 fc0 sc1 ls0 ws0"> add(button_stop); </div><div class="t m0 x3 h8 y27 ff3 fs4 fc0 sc1 ls0 ws0"> add(text); </div><div class="t m0 x3 h8 y28 ff3 fs4 fc0 sc1 ls0 ws0"> button_play<span class="_ _4"></span>.setEnabled(false);</div><div class="t m0 x3 h8 y29 ff3 fs4 fc0 sc1 ls0 ws0"> button_loop.setEnabled(false); </div></div></div><div class="pi" data-data='{"ctm":[1.611850,0.000000,0.000000,1.611850,0.000000,0.000000]}'></div></div>
</body>
</html>