Click to See Complete Forum and Search --> : how to import java class to applet?


mce16
September 25th, 2000, 09:03 PM
i am using microsoft VJ++ and i have problems trying to call myJava class from my java applet program. I can't put the myJava class implementation in the same workspace as my applet class. How to import myJava class to my workspace so that in my java applet implemtation, i can call myJava className = new myJava .... something like that.. hope somebody can help me!

santyns
September 27th, 2000, 10:41 PM
Hi!
If your mainclass.class is in a sub-directory (say, sub_dir), then you can call the class from your applet using the following HTML code :
<html>
<body>
<applet codebase=sub_dir code=sub_dir/mainclass.class width=500 height=500>
</applet>
</body>
</html>

If you find this helpful, please rate this!
Good Luck!

daileyps
September 29th, 2000, 10:17 AM
Do you have a sample applet running this way (with the sub_dir specified) that you can share? I too am having trouble running applets.
Thanks!

santyns
September 30th, 2000, 12:46 AM
Hi!
The code for the html file in (say)
c:\here directory:
<applet
codebase = "\\dis" code = "AppletTest" height = 200 width=300>
</applet>
"dis" is the sub_dir of "here".
Have the class file of the below example java code in the "dis" directory. The code of the java program is:
import java.awt.*;
import javax.swing.*;

public class AppletTest extends JApplet
{
public void init()
{
//do anything!
}

public void paint(Graphics g)
{
g.drawString("Hello!",50,50);
}
}

If you have the HTML file as I have, you'll be fine.
Please rate this if it works for you too!