ClassNotFoundException错误Java Applet

时间:2013-12-23 02:06:38

标签: java applet

我正在做一个简单的音频/图像Java Applet,它在Netbeans中运行良好,但我不能让它在Web浏览器中运行。我不知道我错过了什么,并在网站上搜索答案。

我的java代码:

package web401wk5;

// Imports the AudioClip abstraction http://docs.oracle.com/javase/7/docs/api/java/applet/AudioClip.html
import java.applet.*;

 // Imports the classes for creating user interfaces http://docs.oracle.com/javase/7/docs/api/java/awt/package-summary.html
import java.awt.*;

// Imports the Even user interface element
import java.awt.Event;

/**
 *
 * @author Learning Team B
 */

 // Public class that extends the applet class
 public class Web401wk5 extends Applet {

     // Sets the AudioClip variable as audioClip
    AudioClip audioClip;
    // Sets the variables for the audio buttons
    Button play, loop, stop;
    // Sets the variable to display the image
    Image logo;

    // Initializes the applet
    public void init() {

        // The getImage class calls the image and displays it
        logo = getImage(getCodeBase(), "http://localhost/web401/FB_Logo.jpg");

        //This sizes the applet
        resize(300, 300);



        // The audioClip section retreives the sound clip via an Absolute URL (Requires local server such as XAMPP)
        audioClip = getAudioClip(getCodeBase(), "http://localhost/web401/bnsg.au");

        // Creates the interface GUI
        add(play = new Button("play"));
        add(loop = new Button("loop"));
        add(stop = new Button("pause"));
    }

    // This section adds the BRS logo to the applet
    public void paint(Graphics g) {

        // Gets the width of the image
        int width = logo.getWidth(this);

        // Gets the height of the image
        int height = logo.getHeight(this);

        // Draws a rectangle around the image
        g.drawRect(52, 52, width + 10, height + 10);

        // Places the image inside of the rectangle
        g.drawImage(logo, 57, 57, width, height, this);

    }

    // Creates the boolean event handler
    public boolean handleEvent(Event event) {

        // If statement to trigger the play method of AudioClip
        if (event.target == play) {
            audioClip.play();
            return true;
        }

        // If statement to trigger the loop method of AudioClip
        if (event.target == loop) {
            audioClip.loop();
            return true;
        }

        // If statement to trigger the stop method of AudioClip ** please note that AudioClip does not have a Pause method, so pause is mimmicked with a stop button.
        if (event.target == stop) {
            audioClip.stop();
            return true;
        }
        return super.handleEvent(event);
    }
}

我的HTML代码:

<object type="application/x-java-applet" archive="http://localhost/web401wk5.jar" width="300" height="300">
<param name="codebase" value="http://localhost/" />
<param name="code" value="Web401wk5.class" />   
Applet did not load.  Please ensure you are running this on in a localhost or web server environment.
</object> 

这是一个大学课程。提前感谢您提供任何可能的帮助。

0 个答案:

没有答案