📄 java applet实现声音和图像的协调-开发频道-java-天极网.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0038)http://www.yesky.com/477/1844977.shtml -->
<HTML lang=zh-CN xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>Java Applet实现声音和图像的协调-开发频道-Java-天极网</TITLE>
<META
content="Java Applet实现声音和图像的协调,开发者网络瞄准中国程序员群体,涵盖软件开发的各个技术层面,从Windows下的应用程序开发,到Java、Web开发、游戏开发和移动开发领域,均有相关教程和实例、技巧。 "
name=description>
<META content="Java Applet实现声音和图像的协调,软件开发,嵌入式开发,java开发工具,驱动开发,软件工程,IBM,微软,数据库"
name=keywords>
<META content="天极网 | 全球中文IT第一门户" name=author>
<META content="天极网 | 全球中文IT第一门户" name=Copyright>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META http-equiv=Content-Language content=zh-CN><LINK media=all
href="Java Applet实现声音和图像的协调-开发频道-Java-天极网.files/y_mobile_content.css"
type=text/css rel=stylesheet>
<SCRIPT src="Java Applet实现声音和图像的协调-开发频道-Java-天极网.files/showlay.js"></SCRIPT>
<META content="MSHTML 6.00.2900.2963" name=GENERATOR></HEAD>
<BODY><!--页面头部--><!--头部-->
<DIV>
<SCRIPT
src="Java Applet实现声音和图像的协调-开发频道-Java-天极网.files/kingsoft-kuanban-071105.js"></SCRIPT>
</DIV>
<DIV id=topmenu><A href="http://www.yesky.com/">Yesky首页</A>| <A
href="http://product.yesky.com/">产品报价</A>| <A
href="http://cseek.yesky.com/">行情</A>| <A href="http://mobile.yesky.com/">手机</A>
| <A href="http://digital.yesky.com/">数码</A> | <A
href="http://notebook.yesky.com/">笔记本</A> | <A
href="http://pc.yesky.com/">台式机</A> | <A href="http://diy.yesky.com/">DIY硬件</A>
| <A href="http://oa.yesky.com/">外设</A> | <A href="http://net.yesky.com/">网络</A>
| <A href="http://dh.yesky.com/">数字家庭</A> | <A
href="http://lab.yesky.com/">评测</A> | <A href="http://soft.yesky.com/">软件</A> |
<A href="http://fashion.yesky.com/">e时代</A> | <A
href="http://game.yesky.com/">游戏</A> | <A href="http://pic.yesky.com/">图片</A> |
<A href="http://desktop.yesky.com/">壁纸</A> | <A
href="http://q.yesky.com/">群乐</A> | <A href="http://my.yesky.com/">社区</A> | <A
href="http://blog.yesky.com/">博客</A> | <A
href="http://www.mydown.com/">下载</A></DIV>
<DIV id=topbox>
<DIV class=tleft><A href="http://www.yesky.com/"><IMG alt=天极Yesky_全球中文IT第一门户
src="Java Applet实现声音和图像的协调-开发频道-Java-天极网.files/logo.gif" border=0></A></DIV>
<DIV class=tad><SPAN id=ad1></SPAN></DIV>
<DIV id=search>
<DIV>
<FORM name=searchform action=http://search.chinabyte.com/search method=get
target=_blank><INPUT id=searchzz onmouseover=this.focus() onfocus=this.select()
name=q><INPUT type=hidden value=GB2312 name=encoding><INPUT type=hidden
value=connect name=dir><INPUT type=hidden value=20002 name=cid><INPUT id=search_btn type=submit value=天极搜索> </FORM></DIV>
<DIV class=tdq>
<DIV class=rightarea><A href="http://bj.yesky.com/">北京</A> <A
href="http://hd.yesky.com/">上海</A> <A href="http://gd.yesky.com/">广州</A> <A
href="http://sz.yesky.com/">深圳</A><BR><A href="http://cd.yesky.com/">成都</A> <A
href="http://cq.yesky.com/">重庆</A> <A href="http://sy.yesky.com/">沈阳</A> <A
href="http://xa.yesky.com/">西安</A> </DIV>
<DIV class=rightarea_right><A
href="http://my.yesky.com/">用户<BR>登录</A></DIV></DIV></DIV>
<DIV class=tright>
<DIV class=box1>
<SCRIPT src="Java Applet实现声音和图像的协调-开发频道-Java-天极网.files/content_text_ad.js"
type=text/javascript></SCRIPT>
</DIV></DIV></DIV>
<SCRIPT src="Java Applet实现声音和图像的协调-开发频道-Java-天极网.files/flash.js"
type=text/javascript></SCRIPT>
<!--导航条-->
<DIV id=location>
<DIV class=loleft>您现在的位置: <A href="http://www.yesky.com/" target=_self>天极网</A>
> <A href="http://dev.yesky.com/" target=_self>开发频道</A> > Java
Applet实现声音和图像的协调</DIV>
<DIV class=adright><SPAN id=ad2></SPAN></DIV></DIV><!--内容块开始-->
<DIV id=conbox><!--左边开始-->
<DIV id=conleft>
<DIV id=contopla1>
<DIV id=__001>
<DIV class=qkong></DIV>
<DIV class=qw1>全文</DIV>
<DIV class=zkong>
<DIV class=kl></DIV>
<DIV class=bj><A href="http://www.yesky.com/477/1844977.shtml#pls"
target=_self>评论</A></DIV>
<DIV class=kr></DIV>
<SCRIPT type=text/javascript>
var titiepic ="#";
if (titiepic!="#")
{
document.write("<div class=\"kl\"></div><div class=\"bj\"><a href=\"#\" target=\"_blank\">图片</a></div><div class=\"kr\"></div>");
}
</SCRIPT>
</DIV></DIV></DIV>
<DIV class=topadbg style="PADDING-BOTTOM: 5px"><SPAN id=ad10></SPAN></DIV><A
name=top></A>
<DIV id=contitle>
<H1>Java Applet实现声音和图像的协调</H1></DIV>
<DIV id=conauthor><SPAN>2004-08-24 17:09 </SPAN><SPAN>作者: 务实 </SPAN><SPAN>出处:
天极网 </SPAN><SPAN>责任编辑:<A title=向本编辑提问
href="http://comments.yesky.com/t/·½ÖÛ/6,324/1844977.shtml" target=_blank>方舟</A>
</SPAN></DIV>
<DIV class=topadbg><SPAN id=ad9></SPAN></DIV>
<DIV id=conneirong><SPAN id=ad3></SPAN>
<DIV class=guanggao><SPAN
id=contentAdv></SPAN></DIV> 在有些情况下,可能需要在发生某事件时伴之以声音,尢其是在Applet
中装载图像的同时播放声音,这样将大大地丰富Applet的内容。协调使用图像的声音是十分重要的。<BR><BR> 声音和图像的协调(Appletl.<A
class=bluekey href="http://dev.yesky.com/devjava/"
target=_blank>java</A>)<BR><BR><IFRAME align=center marginWidth=0 marginHeight=0
src="Java Applet实现声音和图像的协调-开发频道-Java-天极网.files/dell-note-inner-scolumn-nb-1.htm"
frameBorder=0 width=360 scrolling=no height=300></IFRAME><BR><BR>
<TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#e6e4dd border=1>
<TBODY>
<TR>
<TD>//源<A class=bluekey href="http://dev.yesky.com/"
target=_blank>程序</A>清单<BR>import java.awt.*;<BR>import
java.applet.*;<BR>import java.util.*;<BR>public class Appletl extends
Applet implements Runnable<BR>{<BR> AudioClip audioClip;<BR> Thread
ShapeThread=null;<BR> Random RandomNumber=new Random( );<BR> Color
ImageColor;<BR> public void init(
)<BR> {<BR> audioClip=getAudioClip(getCodeBase( ), "Sample.AU");//
创建一个AudioClip对象<BR> }<BR> public void start( )<BR> {<BR> if (ShapeThread=
=null)<BR> {<BR> ShapeThread=new Thread(this);<BR> ShapeThread.start(
);<BR> }<BR> }<BR> public void run()<BR> {<BR> while
(true)<BR> {<BR> switch (RandomNumber.nextlnt(5)) {
//把随机数转换为0~4之间的值<BR> case 0:
ImageColor=Color.black;<BR> break;<BR> case 1:
ImageColor=Color.blue;<BR> break;<BR> case 2:
ImageColor=Color.cyan;<BR> break;<BR> case3:
ImageColor=Color.magenta;<BR> break;<BR> case4:
ImageColor=Color.orange;<BR> break;<BR> default:
ImageColor=Color.red;<BR> }<BR> try<BR> {<BR> ShapeThread.sleep(300);
//线程睡眠<BR> }<BR> catch(InterruptedException
e)<BR> {<BR> //忽略异常<BR> repaint();<BR> }<BR> }<BR> public void
paint(Graphics
g)<BR> {<BR> g.setColor(ImageColor);<BR> audioClip.play();
//播放声音<BR> switch(RandomNumber.nextlnt(2))
//获取随机数与2整除的余数<BR> {<BR> case0:g.fillRect(25,25,200,200);
//添充一个矩形<BR> break;<BR> default:g.fillOval(25,25,200,200);
//添充一个椭圆<BR> break;<BR> }<BR> }<BR>}</TD></TR></TBODY></TABLE><BR> 该Applet的声音处理非常简单。它首先创建一个AudioClip对象并用getAudioClip把声音文件赋予该对象,然后用AudioClip类的play方法播放声音。该Applet使用Random对象产生随机数。它首先根据随机数确定颜色;然后在paint内根据随机数确定画圆还是画方。Random类的nexsInt函数返回一个随机整数(int型)。该Applet把随机数转换为一个0~4之间的值(在run函数内)和一个0~1之间的值(在paint函数内)。<BR>需把如下的HTML语句放入Appletl.HTML文件,为运行该Appletl做准备。<BR><BR>
<TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#e6e4dd border=1>
<TBODY>
<TR>
<TD><HTML><BR><TITLE>Applet</TITLE><BR><APPLET CODE="Appletl.class"
WIDTH=300
HEIGHT=300><BR></APPLET><BR></HTML></TD></TR></TBODY></TABLE><BR> 编译并运行该Appletl,屏幕上将显示出一个Applet窗口,窗口中不<BR></DIV><!--广告代码开始-->
<SCRIPT>
var ad_cid;
if (window.location.search.substring(1) != "")
{
ad_cid = window.location.search.substring(1);
} else {
ad_cid = 412;
}
</SCRIPT>
<!--小通栏:c-scolumn顶部500*90--><SPAN id=span_ad1>
<SCRIPT language=JavaScript>
document.write("<script src=\"http://vd.yesky.com/html/"+ad_cid+"/"+ad_cid+"_c-scolumn.js\"><\/script>");</SCRIPT>
</SPAN>
<SCRIPT language=JavaScript>
document.getElementById("ad1").innerHTML=document.getElementById("span_ad1").innerHTML;
document.getElementById("span_ad1").innerHTML="";
</SCRIPT>
<!--c-pip文章正文中间240*200--><SPAN id=span_ad3>
<SCRIPT language=JavaScript>
document.write("<script src=\"http://vd.yesky.com/html/"+ad_cid+"/"+ad_cid+"_c-pip.js\"><\/script>");</SCRIPT>
</SPAN>
<SCRIPT>
if(document.getElementById("contentAdv")) {
document.getElementById("contentAdv").innerHTML=document.getElementById("span_ad3").innerHTML;
document.getElementById("span_ad3").innerHTML="";
} else {
document.getElementById("ad3").innerHTML=document.getElementById("span_ad3").innerHTML;
document.getElementById("span_ad3").innerHTML="";
}</SCRIPT>
<!--c-text-1“您现在的位置”右侧文字--><SPAN id=span_ad2>
<SCRIPT language=JavaScript>
document.write("<script src=\"http://vd.yesky.com/html/"+ad_cid+"/"+ad_cid+"_c-text-1.js\"><\/script>");</SCRIPT>
</SPAN>
<SCRIPT language=JavaScript>
document.getElementById("ad2").innerHTML=document.getElementById("span_ad2").innerHTML;
document.getElementById("span_ad2").innerHTML="";
</SCRIPT>
<!--c-column-2“标题”上面的广告--><SPAN id=span_ad10>
<SCRIPT language=JavaScript>
document.write("<script src=\"http://vd.yesky.com/html/"+ad_cid+"/"+ad_cid+"_c-column-2.js\"><\/script>");</SCRIPT>
</SPAN>
<SCRIPT language=JavaScript>
document.getElementById("ad10").innerHTML=document.getElementById("span_ad10").innerHTML;
document.getElementById("span_ad10").innerHTML="";
</SCRIPT>
<!--c-column-1“摘要”下面的广告--><SPAN id=span_ad9>
<DIV id=ad9ad>
<SCRIPT language=JavaScript>
document.write("<script src=\"http://vd.yesky.com/html/"+ad_cid+"/"+ad_cid+"_c-column-1.js\"><\/script>");</SCRIPT>
</DIV></SPAN>
<SCRIPT language=JavaScript>
document.getElementById("ad9").innerHTML=document.getElementById("span_ad9").innerHTML;
document.getElementById("span_ad9").innerHTML="";
</SCRIPT>
<DIV class=clear></DIV><!--产品图片开始--><!-- Error --><!--产品图片结束-->
<DIV class=clear></DIV>
<STYLE>.box10 {
BORDER-RIGHT: #eaeaea 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #eaeaea 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; BORDER-LEFT: #eaeaea 1px solid; LINE-HEIGHT: 24px; PADDING-TOP: 5px; BORDER-BOTTOM: #eaeaea 1px solid; TEXT-ALIGN: left
}
.box10 LI {
LIST-STYLE-POSITION: outside; LIST-STYLE-TYPE: none
}
</STYLE>
<DIV class=box10>
<SCRIPT src="Java Applet实现声音和图像的协调-开发频道-Java-天极网.files/art_sdk.js"></SCRIPT>
</DIV>
<DIV class=clear></DIV>
<SCRIPT>
var key="Java";
</SCRIPT>
<SCRIPT
src="Java Applet实现声音和图像的协调-开发频道-Java-天极网.files/product_search.js"></SCRIPT>
<!--广告代码结束-->
<DIV id=ad7ad><SPAN id=ad7></SPAN></DIV>
<DIV class=clear></DIV>
<DIV id=conlink>
<SCRIPT type=text/javascript>var clipBoardContent = document.URL; function copyUserHomeToClipBoard() { window.clipboardData.setData("Text",clipBoardContent); alert("复制成功,请粘贴到你的QQ/MSN上推荐给你的好友!\r\n\r\n内容如下:\r\n" + clipBoardContent); }</SCRIPT>
<FORM id=feedbackForm name=feedbackForm
action=http://feedback.yesky.com/reader/user/doWelcome.view target=_blank><INPUT
id=refurl type=hidden name=refurl> <INPUT id=reftitle type=hidden name=reftitle>
</FORM>
<SCRIPT type=text/javascript>document.write("<a href=\"http:\/\/dig.yesky.com\" id=\'yeskyDig\' onclick=\"javascript:this.href=\'http:\/\/dig.yesky.com\/ding.php?t=\'+encodeURIComponent(document.title)+\'&u=\'+escape(document.location.href)+\'&ac=ding\';\" target=_blank title=\"此文不错,我顶!\"><b>我顶一下<\/b><\/a> <a onclick='javascript:submitFeedback();' style='cursor:hand;'><font color='#FF0000'><b>我要挑错</b></font></a> <a href=\"#top\" target=\"_self\"><a href=\"javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(yesky=window.open('http://hot.yesky.com/dp.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t)+'&st=2','_blank','scrollbars=no,width=400,height=480,left=75,top=20,status=no,resizable=yes'));yesky.focus();\"title=\"推荐到天极网摘 http://hot.yesky.com [鼠标划选本文摘要,然后点击本图片]\" target=\"_self\">收藏到天极收藏夹</a> <a href=\"JavaScript: copyUserHomeToClipBoard()\" target=\"_self\">复制链接发给好友</a> <a href=\"javascript:window.external.AddFavorite('"+clipBoardContent+"')\" target=\"_self\">加入收藏</a> <a href=\"javascript:window.print()\" target=\"_self\">打印</a> <img src=\"http://image.yesky.com/TLimages/newmobile/titlebg19.gif\" title=\"返回顶部\"/></a>");function submitFeedback() { document.getElementById("refurl").value=document.location.href; document.getElementById("reftitle").value=document.title; document.getElementById("feedbackForm").submit();}</SCRIPT>
</DIV>
<DIV class=clear></DIV><!--评论-->
<SCRIPT language=JavaScript>
<!--
var aid = 1844977;
var channelid = 324;
if (channelid==0) channelid=22;
var tagname = "";
//-->
</SCRIPT>
<SCRIPT language=JavaScript>
if(typeof(channelid) != "undefined") {
document.write("<script language=\"JavaScript\" charset=\"gb2312\" src=\"http://comments.yesky.com/channlereview/6/"+(channelid%5000)+"/"+channelid+".js\"><\/script>");
}
</SCRIPT>
<SCRIPT language=javascript>
<!--
if(typeof(aid) != "undefined") {
document.write("<script language=\"JavaScript\" charset=\"gb2312\" src=\"http://comments.yesky.com/articlereplies/6/"+(aid%5000)+"/"+aid+".js\"><\/script>");
}
//-->
</SCRIPT>
<SCRIPT src="Java Applet实现声音和图像的协调-开发频道-Java-天极网.files/mobile_comment.js"
type=text/javascript></SCRIPT>
<DIV class=clear></DIV><!--相关文章等-->
<DIV id=conrele>
<DIV class=xgleft id=__002>
<DIV class=xgmenus>相关文章</DIV>
<DT><!-- Error --></DT></DIV>
<DIV class=xgright id=__003>
<DIV class=xgmenus>最新更新</DIV>
<DT></DT>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -