bad class file:.\AudioClip.java
file does not contain class AudioClip
Please remove or make sure it appears in the correct subdirectory of the classpath.
我刚开始学JAVA,我按照Java教程中的实例写完之后出现以上问题,我按照书上说的环境变量设置方法设置的,
请教各位高手指点一下小弟。
感激不尽!
----------------------------------------------------------
/*
<applet code="Applet1.class"width=300 height=200>
</applet>
*/
import java.awt.*;
import java.applet.*;
import java.util.*;
public class Applet1 extends Applet implements Runnable
{
AudioClip audioClip;
Thread ShapeThread=null;
Random RandomNumber=new Random();
Color ImageColor;
public void init()
{
audioClip=getAudioClip(getCodeBase(),"吉祥三宝靖远.AU");
}
public void start()
{
if(ShapeThread==null)
{
ShapeThread=new Thread(this);
ShapeThread.start();
}
}
public void run()
{
while(true)
{
switch(RandomNumber.nextInt()%5)
{
case 0: ImageColor=Color.black;
break;
case 1: ImageColor=Color.blue;
break;
case 2: ImageColor=Color.cyan;
break;
case 3: ImageColor=Color.magenta;
break;
case 4: ImageColor=Color.orange;
break;
default: ImageColor=Color.red;
}
try
{
ShapeThread.sleep(300);
}
catch(InterruptedException e)
{
//忽略异常
}
repaint();
}
}
public void paint(Graphics g)
{
g.setColor(ImageColor);
audioClip.play();
switch(RandomNumber.nextInt()%2)
{
case 0: g.fillRect(25,25,200,200);
break;
default: g.fillOval(25,25,200,200);
break;
}
}
}
------------------------------------------------------------
javac Applet1.java
appletviewer Applet1.java
这样运行 我这里是没有问题的 应该是你classpath设置的问题
你的程序里还有几个小错误 编译时报错了 我已经改了
谢谢,已经可以运行了,就是歌曲播放不连贯。
还有我想问一下这样引用正确吗?——import borland.jbc1.layout.*;
import borland.jbc1.control.*;