PDA

Click to See Complete Forum and Search --> : OBJECT tag


GamerMax5
Aug 27th, 2007, 11:50 PM
I'm still having trouble grasping how this thing is supposed to work. I've read numerous tutorials on it and I'm still lost.

I wrote a stupid applet that simply prints a string to the applet. I made a web page that uses the OBJECT tag to display it on the web page. Here is the code that I used:


<html>
<head>
<title>Keyboard Test Applet :: Written by Greg Martin</title>
</head>
<body>
<center>
<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" codebase="http://java.sun.com/products/plugin/autodl/jinstall-1_4_2-windows-i586.cab#Version=1,4,0,0" width="640" height="480">
<param name="code" value="KeyboardTest.class">
<param name="codebase" value="html/">
<param name="type" value="application/x-java-applet;version=1.4">
</object>
</center>
</body>
</html>


This works all fine and dandy however the applet window keeps telling me that the applet failed to initialize. I might be missing something because of it's absolute simplicity but here is the code that I have in the applet:


import java.applet.*;
import java.awt.*;

public class KeyboardTest extends Applet {
public void init() {}

public void paint(Graphics g) {
g.drawString("Press a key...", 20, 20);
}
}


The KeyboardTest class file is located in the same directory that the web page is in so I don't see any problem there but I can't figure out what in the world is going on. Any help would be appreciated. Thanks in avance.

EDIT: And yes I am aware that the class id for the version of Java is lower than what's available but I figured that since I used dynamic versioning, it'd find the more recent one until I figured out how to properly use the OBJECT tag.

ComputerJy
Aug 28th, 2007, 03:02 PM
try <param name="code" value="KeyboardTest" />

remove the .class from the value :D

And if the class file is in the same path as the web page, you should set <param name="codebase" value="html/" /> value to empty string ""

GamerMax5
Aug 30th, 2007, 10:42 AM
I did what you said to do but it's still saying applet uninited. I really do think that it's finding the applet class code regardless of if the extension is there or not. And as far as I can tell, there isn't anything wrong with my applet code. I can't figure out what's going on here. :(

sevenhalo
Aug 30th, 2007, 10:48 AM
Try including:
srctype="application/x-java-applet"
in your Object tag as an an attribute, not just the param.

GamerMax5
Aug 31st, 2007, 11:27 PM
I did that and it still can't initialize the applet. I thought that it might have been the JRE itself so I reinstalled it and it was still doing it. I copied what the Java Console wrote out and here is what it said:

load: class KeyboardTest.class not found.
java.lang.ClassNotFoundException: KeyboardTest.class
at sun.applet.AppletClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadCode(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: \KeyboardTest\class.class (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
at sun.applet.AppletClassLoader.getBytes(Unknown Source)
at sun.applet.AppletClassLoader.access$100(Unknown Source)
at sun.applet.AppletClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 10 more