473,289 Members | 2,040 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

Accessing the DOM API with an Applet (JApplet)

This is an attempt to respond to an older question (several months).
Date: 2002-03-07 13:10:23 PST
Subject: On the Common DOM API and Applets.

The original message was:
LiveConnect and the JSObject technique are Netscape technologies (or
related to). I want an alternate way of accessing the HTML DOM from
Java Applets and to call Methods on the Applets from JavaScript. Chapters 25 and 26 of the Java Plug-in Developer Guide (JDK 1.4)
present such alternatives. What got my attention was the Common DOM
API. "The Common DOM classes allow an application to access the
underlying DOM of the browser through the APIs in the org.w3c.dom and
org.w3c.dom.html packages." There is an example included: DOMService service = null; try{
service = DOMService.getService(MyApplet);
String title = (String) service.invokeAndWait(
new DOMAction(){
public Object run(DOMAccessor accessor)
{
HTMLDocument doc = (HTMLDocument) accessor.getDocument();
return doc.getTitle();
}});
} catch (DOMUnsupportedException e1){
} catch (DOMAccessException e2){
} But there ends the fairy tale. This won't build. getDocument() takes
an Object arg which is not described in the doc and source code. Then
the author goes on to describe the com.sun.browser.dom package which
is in fact the com.sun.java.browser.dom package. And finally, I
haven't had any success in making it work. I got the same result with
Mozilla 0.98 and IE 6.0... Anyone?
yours

I don't know what class you have derived from?
But according to the documentation JApplet interface differs from that
of Applet.
So passing "this" to "DOMAccessor.getDocument( Object )" does not
translate correctly.
So instancing the base of Applet from JApplet and then passing it
seems to do the trick.
public class j_applet1 extends javax.swing.JApplet {
private Applet applet;

/** Initializes the applet j_applet1 */
public void init() {
initComponents();
applet = this;

DOMService service = null;
try {
service = DOMService.getService( applet );
String title = (String) service.invokeAndWait(new
DOMAction() {
public Object run(DOMAccessor accessor) {
// getDocument(Object obj)
Object obj = accessor.getDocument( applet );
if (obj == null) {
return "Object was null";
}
HTMLDocument doc = (HTMLDocument) obj;
if (doc == null) {
return "HTMLDocument was null";
}
return doc.getTitle();
}
});
jTextField1.setText(title + new String("DDDD"));
}
catch (DOMUnsupportedException e1) {
jTextField1.setText("E1" + e1.getMessage());
}
catch (DOMAccessException e2) {
jTextField1.setText("E2" + e2.getMessage());
}
catch(Exception e3) {
jTextField1.setText("E3" + e3.toString());
}
}

This seemed to answer the question of why passing a rerfrence of
"this" derived from JApplet fails when passed to methiods expecting an
Applet interface.

This was a tough one.
Jul 17 '05 #1
0 5570

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: dB | last post by:
I want to load an applet locally from the client's hard drive from an html/jsp page served by Tomcat on the local machine or a remote server. The motivation is that I need to print to the local...
0
by: Ike | last post by:
I have a signed JApplet which has a JTextArea wherein one can put Jython Script. Upon clicking a JButton, the script is executed. The script which executes to code is listed below. If I run the...
0
by: shanmukhi | last post by:
Hi All I got a problem in running java programs. i am not able to run java applet while running i got a problem as Loading Java Applet Failed java.lang.NoClassDefFoundError: App (wrong...
0
by: shanmukhi | last post by:
Hi All I got a problem in running java Applet i am not able to run java applet while running i got a problem as Loading Java Applet Failed java.lang.NoClassDefFoundError: App (wrong name:...
1
by: dishal | last post by:
Can anyone help me please? How do I convert these codes to launch from a JFrame instead of a Java Applet? A simple program where the user can sketch curves and shapes in a variety of...
4
by: tudyfruity18 | last post by:
I'm suppose to write an applet that contains two buttons Investment calculator and Loan Calculator. When the Investment Calculator button is clicked, a frame appears in a new window for calculating...
1
by: sheephead86 | last post by:
Hi, I'm pretty new to java, and I have a small problem involving drawing a rectangle on a java applet.Firstly this is not a plea for someone to help me with this peice of work, I just need pointing...
8
by: drsmooth | last post by:
this is rather frustrating...i have tried numerous different things in a futile attempt to get a japplet packaged in a jar file to load on my site. everytime i try a new thing i get: load:...
2
by: ManidipSengupta | last post by:
Hi, a few (3) questions for the Java experts, and let me know if this is the right forum. It deals with 100% java code (reason for posting here) but manages a Web browser with Javascript. Thanks in...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.