CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 1999
    Posts
    272

    how to import java class to applet?

    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!


  2. #2
    Join Date
    Mar 2000
    Posts
    10

    Re: how to import java class to applet?

    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!


  3. #3
    Join Date
    Mar 2000
    Posts
    123

    Re: how to import java class to applet?

    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!


  4. #4
    Join Date
    Mar 2000
    Posts
    10

    Re: how to import java class to applet?

    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!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured