在有些情況下
聲音和圖像的協調(Appletl
//源程序清單
import java
import java
import java
public class Appletl extends Applet implements Runnable
{
AudioClip audioClip;
Thread ShapeThread=null;
Random RandomNumber=new Random( );
Color ImageColor;
public void init( )
{
audioClip=getAudioClip(getCodeBase( )
}
public void start( )
{
if (ShapeThread= =null)
{
ShapeThread=new Thread(this);
ShapeThread
}
}
public void run()
{
while (true)
{
switch (RandomNumber
case
break;
case
break;
case
break;
case
break;
case
break;
default: ImageColor=Color
}
try
{
ShapeThread
}
catch(InterruptedException e)
{
//忽略異常
repaint();
}
}
public void paint(Graphics g)
{
g
audioClip
switch(RandomNumber
{
case
break;
default:g
break;
}
}
}
該Applet的聲音處理非常簡單
需把如下的HTML語句放入Appletl
<HTML>
<TITLE>Applet</TITLE>
<APPLET CODE=
</APPLET>
</HTML>
編譯並運行該Appletl
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26228.html