Click to See Complete Forum and Search --> : Applets 101: Converting a Java Application into an Applet


daileyps
September 28th, 2000, 03:35 PM
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/1.1.1/jinstall-111-win32.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/1.1.1/plugin-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/String;)V 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 :-)

poochi
September 28th, 2000, 04:46 PM
> 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...

daileyps
September 29th, 2000, 08:41 AM
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.

poochi
September 29th, 2000, 09:25 AM
Can you post the code ?

daileyps
September 29th, 2000, 09:31 AM
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!!!