简体   繁体   中英

How to save code for Java applets

I am thoroughly confused as to what part of my code I need to put onto a website in order for me to embed this as a gadget in Google Sites. One source that I found said that I should have both my main class as one file and my whole project as another. I am using Google Code, and have gotten my main class (which is saved as a .java file), and the rest of my project (which is saved as a .jar file) onto the code file cabinet.

Currently, I am getting an error with my code not being able to find the class that contains my main(String[] args) {} method. Officially, it is a ClassNotFoundException, with the text Main.java, which is the name of my 'code' in HTML. If you want to see it for a reference, here is the HTML that I am using for my Google site:

<applet name="UnderLD" code="Main.java" archive="UnderLudumDare.jar"
    codebase="http://wierd0games.googlecode.com/svn/"
     width = 300 height = 168>
Sorry, this Applet could not be started. Please make sure that Java 1.4.2 (or later) is installed and active in your browser (<a href="http://java.sun.com/getjava">Click here to install Java now</a>)
</applet>

However when I paste the link for the codebase in my brower, the java.Main class (the one with my main method) is the first on the list. To me, I am doing everything correctly according to all of the tutorials I have found, so what am I doing wrong?

code should be the name of class file for the applet, not the name of the source file . The trailing .class is optional but Sun now recommends omitting it. All of the main browsers will work with or without the .class suffix.

So both of the following should work, provided Main.class is in the root of the jar file:

code="Main.class"

code="Main"

Source Using applet, object and embed Tags

code = appletFile

This required attribute gives the name of the file that contains the applet's compiled Applet subclass. This file is relative to the base URL of the applet. It cannot be absolute. One of code or object must be present. The value appletFile can be of the form classname.class or of the form packagename.classname.class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM