Having problems creating/embeding a JApplet
I'm having some trouble creating JApplet, and I've googled quite a bit, but I'm obviously missing something big.
I've created an Eclipse project, with 6 packages, and one of them (named 'gui') has two important files. The first one is called ComplexApp.java, which does the initialization of the app (a开发者_如何学JAVAnd has a "public static void main"), and a second one, ComplexApplet.java does the same thing, except that it contains init() and start() (and lacks main()). The applet and the app both start normally in eclipse.
So now, I exported the whole project as a .jar file. The first thing I've noticed is that I never specified which .java class should be used to start the applet (I was at one point asked to select a class containing main(), but I've skipped that, since applets don't have main(), only init()/start()/... right?
If I try to start the generated .jar file (using Jar launcher), I receive a message saying "Failed to load Main-Class manifest attribute", which I guess is normal. So I've created a .jnlp file, and when I start it manually (or embed it on a html), I receive an error: "The field href has an invalid value: Complex.jar". Here is the jnlp:
<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="" href="">
<information>
<title>Complex numbers</title>
<vendor>ETF</vendor>
</information>
<resources>
<!-- Application Resources -->
<j2se version="1.6+"
href="http://java.sun.com/products/autodl/j2se" />
<jar href="Complex.jar"/>
</resources>
<applet-desc
name="Complex numbers"
main-class="gui.ComplexApplet"
width="800"
height="700">
</applet-desc>
<update check="background"/>
</jnlp>
So, can anyone help me? Pretty please? :)
Thanks.
I don't know jnlp-files, but in a html-file, you would write:
<applet
code="gui.ComplexApplet"
archive="./Complex.jar"
HEIGHT="240"
WIDTH="480"
>
</applet>
with ./ only, if it is in the current directory. Else maybe an absolute path is preferable. If viewn in the browser or appletviewer, then ./ is ok, if the jar is at the same place, the html-file is.
main-class looks wrong, since you don't want to use the main-class.
精彩评论