Click to See Complete Forum and Search --> : Java applet with ASP.Net


Lilac
11-02-2006, 06:16 AM
can I add a "java applet" to be included in an asp.net page?

if yes, how can I do it?

I used to add it to the HTML page using this code

<APPLET
code = "JavaAppletClassName.class"
width = "800"
height = "600">
</APPLET>

>>>the applet is working correctly


but when I paste this code in ASP.Net page 2 errors occurred:

1- Error 1 Validation (Internet Explorer 6): Attribute 'width' is not a valid attribute of element 'applet'.

2- Error 2 Validation (Internet Explorer 6): Attribute 'height' is not a valid attribute of element 'applet'.

when I try to remove these attribute,and then compile the page, an error msg appeared:

Unable to attach. The binding handle is invalid.

Do u want to continue any way?



when I press yes, a very small square displayed,with an X at the top, and the status bar of the browser said :

Applet not inited


and plz I need a free hosting site to test what I've done



thanks in advance

TheBearMay
11-02-2006, 08:21 AM
From the HTML 4.01 specification: (http://www.w3.org/TR/html4/struct/objects.html#edef-APPLET)

13.4 Including an applet: the APPLET element
APPLET is deprecated (with all its attributes) in favor of OBJECT.

See the Transitional DTD for the formal definition.

Attribute definitions

codebase = uri [CT]
This attribute specifies the base URI for the applet. If this attribute is not specified, then it defaults the same base URI as for the current document. Values for this attribute may only refer to subdirectories of the directory containing the current document. Note. While the restriction on subdirectories is a departure from common practice and the HTML 3.2 specification, the HTML Working Group has chosen to leave the restriction in this version of the specification for security reasons.
code = cdata [CS]
This attribute specifies either the name of the class file that contains the applet's compiled applet subclass or the path to get the class, including the class file itself. It is interpreted with respect to the applet's codebase. One of code or object must be present.
name = cdata [CS]
This attribute specifies a name for the applet instance, which makes it possible for applets on the same page to find (and communicate with) each other.
archive = uri-list [CT]
This attribute specifies a comma-separated list of URIs for archives containing classes and other resources that will be "preloaded". The classes are loaded using an instance of an AppletClassLoader with the given codebase. Relative URIs for archives are interpreted with respect to the applet's codebase. Preloading resources can significantly improve the performance of applets.
object = cdata [CS]
This attribute names a resource containing a serialized representation of an applet's state. It is interpreted relative to the applet's codebase. The serialized data contains the applet's class name but not the implementation. The class name is used to retrieve the implementation from a class file or archive.

When the applet is "deserialized" the start() method is invoked but not the init() method. Attributes valid when the original object was serialized are not restored. Any attributes passed to this APPLET instance will be available to the applet. Authors should use this feature with extreme caution. An applet should be stopped before it is serialized.

Either code or object must be present. If both code and object are given, it is an error if they provide different class names.
width = length [CI]
This attribute specifies the initial width of the applet's display area (excluding any windows or dialogs that the applet creates).
height = length [CI]
This attribute specifies the initial height of the applet's display area (excluding any windows or dialogs that the applet creates).

Attributes defined elsewhere

* id, class (document-wide identifiers)
* title (element title)
* style (inline style information)
* alt (alternate text)
* align, hspace, vspace (visual presentation of objects, images, and applets)

This element, supported by all Java-enabled browsers, allows designers to embed a Java applet in an HTML document. It has been deprecated in favor of the OBJECT element.

The content of the APPLET acts as alternate information for user agents that don't support this element or are currently configured not to support applets. User agents must ignore the content otherwise.

DEPRECATED EXAMPLE:
In the following example, the APPLET element includes a Java applet in the document. Since no codebase is supplied, the applet is assumed to be in the same directory as the current document.

<APPLET code="Bubbles.class" width="500" height="500">
Java applet that draws animated bubbles.
</APPLET>

This example may be rewritten with OBJECT as follows:

<P><OBJECT codetype="application/java"
classid="java:Bubbles.class"
width="500" height="500">
Java applet that draws animated bubbles.
</OBJECT>

Initial values may be supplied to the applet via the PARAM element.

DEPRECATED EXAMPLE:
The following sample Java applet:

<APPLET code="AudioItem" width="15" height="15">
<PARAM name="snd" value="Hello.au|Welcome.au">
Java applet that plays a welcoming sound.
</APPLET>

may be rewritten as follows with OBJECT:

<OBJECT codetype="application/java"
classid="AudioItem"
width="15" height="15">
<PARAM name="snd" value="Hello.au|Welcome.au">
Java applet that plays a welcoming sound.
</OBJECT>

One note though, you should include the units as part of the width and height.

Lilac
11-02-2006, 08:47 AM
but this code is enough to make the applet works correctly with HTML page

<APPLET
code = "JavaAppletClassName.class"
width = "800"
height = "600">
</APPLET>

but the problem is when I try to add it to an asp.net page

I tried to open the sources of some sites designed with asp.net and include applets, and I noticed that they use the same attributes I used to use with HTML coding!!!!

but it doesn't work with me!!

TheBearMay
11-02-2006, 11:02 AM
Are you writing it out using the ASP.Net:


<%= '<APPLET code = "JavaAppletClassName.class" width = "800" height = "600"> </APPLET>' %>

or is it part of the page template:


<% asp.net code
....
%>
<APPLET
code = "JavaAppletClassName.class"
width = "800"
height = "600">
</APPLET>
....

Lilac
11-02-2006, 07:25 PM
just like the second code

agent_x91
11-03-2006, 05:53 AM
Applet tags are deprecated? I didn't realise that. Not often I use applets. However, if it's working normally I see no reason why it shouldn't work on an asp page. Maybe you should ask in the ASP forum.