CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2000
    Posts
    123

    Applets 101: Converting a Java Application into an Applet

    HELP! I have read, and read, and read articles/documentation from the sun site and can't figure this out. I have an application that runs beautifully standalone, but I need to convert it to an applet. I've created an applet .java program to wrap around it, I've used the HTML converter, etc., but can't get it to run in the browser. My base application is an extension of JFrame implementing Printable, with several components, dialogs, etc. (Swing). Here's my applet code:

    import javax.swing.*;
    import java.awt.*;
    import java.applet.*;
    import Attachments;

    public class AttachmentsApplet extends JApplet {

    public void init() {

    String vers = System.getProperty("java.version");
    final Applet thisApplet = this;

    if (vers.compareTo("1.1.2") < 0) {
    System.out.println("!!!WARNING: Swing must be run with a " +
    "1.1.2 or higher version VM!!!");
    }

    String[] atParm = {"025", "PROD", "BMX100"};
    Attachments at = new Attachments(atParm);
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(at, BorderLayout.CENTER);
    validate();
    repaint();

    }

    }

    And here's my converted html:

    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
    <html>
    <head>
    <title>Attachments</title>
    </head>
    <body>

    <OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
    WIDTH = 695 HEIGHT = 525 codebase="http://java.sun.com/products/plugin/....cab#Version=1,1,1,0">
    <PARAM NAME = CODE VALUE = AttachmentsApplet >

    <PARAM NAME="type" VALUE="application/x-java-applet;version=1.1">
    <COMMENT>
    <EMBED type="application/x-java-applet;version=1.1" java_CODE = AttachmentsApplet WIDTH = 695 HEIGHT = 525 pluginspage="http://java.sun.com/products/plugin/...n-install.html"><NOEMBED></COMMENT>

    </NOEMBED></EMBED>
    </OBJECT>

    <APPLET CODE = AttachmentsApplet WIDTH = 695 HEIGHT = 525 >
    </APPLET>

    </body>
    </html>

    And here's the error I get in the java console:


    java.lang.NoSuchMethodError: Attachments: method <init>([Ljava/lang/StringV not found
    at AttachmentsApplet.init(AttachmentsApplet.java:21)
    at sun.applet.AppletPanel.run(AppletPanel.java:342)
    at java.lang.Thread.run(Thread.java:479)

    Any assistance would be GREATLY appreciated!!!
    Thank you so much in advance :-)




  2. #2
    Join Date
    Sep 1999
    Location
    Madurai , TamilNadu , INDIA
    Posts
    1,024

    Re: Applets 101: Converting a Java Application into an Applet


    > Attachments at = new Attachments(atParm);

    I think "Attachments" class doesnt have a constructor which takes string array as an argument. I think you are trying to make a call to "main" method.

    If i were you what i would do is , i will create a content panel to put all my controls and
    the functionalities and i will attach that panel to JFrame or JApplet , wherever i want.

    > getContentPane().add(at, BorderLayout.CENTER);

    You cannot add a window inside a container. You will get exception at runtime.

    Poochi...


  3. #3
    Join Date
    Mar 2000
    Posts
    123

    Re: Applets 101: Converting a Java Application into an Applet

    Actually it does have a constructor which takes string array as an argument. Like I said before, it works fine when I call in in this manner from another java application. I don't know what I am doing wrong.


  4. #4
    Join Date
    Sep 1999
    Location
    Madurai , TamilNadu , INDIA
    Posts
    1,024

    Re: Applets 101: Converting a Java Application into an Applet


    Can you post the code ?


  5. #5
    Join Date
    Mar 2000
    Posts
    123

    Re: Applets 101: Converting a Java Application into an Applet

    It is big...I'll email it to you...but I have gotten further...changed the html to include paths and now getting permissions error? Not sure if I have syntax or environment issue...forwarding .zip file shortly. Maybe you could respond with the lines of code in error. THIS NEWBIE REALLY APPRECIATES THE ASSISTANCE!!!


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