How do I put my Java class applet into an HTML document? I made this test one with
import java.awt.*;
import javax.swing.*;
public class HelloWorld extends JApplet {
public void init(Graphics g) {
super.paint(g);
g.drawString("Hello World!", 25, 25);
}
}It doesn't get any errors from the compiler (in my case, the Terminal app) or the Java console that launches automatically. The HTML file is
<html>
<head>
<style type="text/css">
#lbl
{
color:red;
text-align:center;
font-size:1em;
}
</style>
<title>Java Applet Test</title>
</head>
<body>
<applet code="helloworld.class" name="applet" archive="helloworld.jar" width="400" height="100">
Your browser does not support Java
</applet>
<embed src="helloworld.jar width="400" height="100" />
<p id="lbl>It works?</p>
</body>
</html>Yeah, I know I didn't need the stylesheet. I just felt like it. Anyway, I just get a grey box. The file's' called helloworld.jar if it matters. And yes, I've got the .jar file, and every file's on my Desktop.
Help, please, and thanks in advance.
Last edited by maxskywalker (2011-10-24 14:09:25)
Offline
Wow. That sunk into page 10 pretty fast.
Offline
don't you need to have a .jar not a .class
Offline
veggieman001 wrote:
don't you need to have a .jar not a .class
I really have no idea. How do you make .jar files?
Last edited by maxskywalker (2011-10-23 14:43:35)
Offline
maxskywalker wrote:
veggieman001 wrote:
don't you need to have a .jar not a .class
I really have no idea. How do you make .jar files?
Bump.
Offline
Yeah, you need to make a JAR file to run in a web browser. Look at this or Google for it.
Offline
meowmeow55 wrote:
Yeah, you need to make a JAR file to run in a web browser. Look at this or Google for it.
Thanks! Just made my .jar file and I'll revise the HTML now!
Offline
Hmm... it says it can't find the file…
Offline
Okay, now I redid it (see the original post for changes) to include both the class and jar file (not to mention a Java-not-enabled message), and I don't get the error message. Just a big gray box (400x100px to be exact) with nothing in it where the applet should be. That one applet-debugging site (completely useless) was right when it said that it was almost as annoying as a Blue Screen of Death.
Offline
Just tried replacing the file names in the HTML file with "Desktop/file_name", just because the VM said that the home directory was my user (didn't know what that meant). Anyway, I got an error message and switched it back; but we know that my Java VM error handler isn't just broken.
Offline
veggieman001 wrote:
that's weird... :\
You said it.
Offline
Okay, just changed the <applet> to <embed src="helloworld.jar" /> and it says I need an updated version of Java. Here's the thing: I use a Mac, and it says that Mac OS X has its own Java player which I update through Software Update, but when I run a software update, it says everything's fine. I'm downloading it on my Windows now, and will post the results here.
Offline
Okay, I just downloaded the latest version of Java (java VM and deployment toolkit), but it still says I'm missing a plug-in. What else is there?
Offline
IS there anything else?
Offline
Bump … … … … … … … … … … … … … … … …
Offline
I think thats enough bumps....
Offline
CheeseMunchy wrote:
I think thats enough bumps....
Maybe. But then why isn't it working?
Offline