473,508 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5583

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

Similar topics

0
3054
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
1308
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
1467
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
1465
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
6599
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
7792
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
2366
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
3234
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
3429
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
7114
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7034
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5045
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1544
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.