Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion LiveConnect applet crashing after page reload, please help
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
DKM  
View profile  
 More options Jun 11 2005, 10:02 pm
Newsgroups: comp.lang.java.help, comp.lang.java.programmer, comp.lang.javascript
From: "DKM" <debashishkmis...@hotmail.com>
Date: 11 Jun 2005 19:02:19 -0700
Local: Sat, Jun 11 2005 10:02 pm
Subject: LiveConnect applet crashing after page reload, please help
Here are the source code files to a Java applet that utilizes
LiveConnect to communicate with Javascript, and the HTML file.

The thing works both in IE 6.0 and FireFox 1.4. but with some problems.
IE crashes when one refreshes the page or leave the page. This happens
only after calling the Java method more than once. It does not crash if
the Java method is called just once and then the page is refreshed.

FireFox does not crash at all and no error whatsoever. However, it
takes a good minute or two to display the newly created element. And,
if during that time  if one calls the Java method, it gives an error
and it never works afterwords. But, once the Java method returns after
the first time, it works robustly no matter how many times the Java
method is called or if the page is refreshed or closed.

Can any LiveConnect guru please take a look at this code and let me
know whats wrong with it.

Thank you very much in advance.

D.K. Mishra

========  Hello.class  ========
import java.applet.Applet;
import java.awt.Graphics;
import netscape.javascript.*;

public class Hello extends Applet {

        private JSObject win;
        private JSObject doc;

        public void init() {
        }

        public void start() {
                win = JSObject.getWindow(this);
                doc =(JSObject) win.getMember("document");
        }

        //A set of 2 overloaded helper methods to create object array to pass
        // as the 2nd argument to doc.call(string,Object[]).
        public Object[] objArr(JSObject jso) {
                Object[] ret = {jso};
                return ret;
        }
        public Object[] objArr(String str) {
                Object[] ret = {str};
                return ret;
        }

        //This cretes a filled HTML Tag like <p>Hello</p> or
        //<i>world!</i>.
        public JSObject createFilledTag(String strTag, String strText) {
                JSObject        fragDoc = (JSObject)
doc.call("createDocumentFragment",null);
                JSObject tagEle = (JSObject)
doc.call("createElement",objArr(strTag));
                JSObject tagTextEle =
(JSObject)doc.call("createTextNode",objArr(strText));
                tagEle.call("appendChild",objArr(tagTextEle));
                fragDoc.call("appendChild",objArr(tagEle));
                return fragDoc;
        }

        //This method is called from javascript. It inserts
        //*** Hello World! ***" into the empty <p id="para"></p>
        //element
     public void insertText(String str) {
                JSObject paraEle = (JSObject) doc.call("getElementById",
objArr(str));
                JSObject tmpEle = createFilledTag("b","*** Hello World! ***");
                paraEle.call("appendChild",objArr(tmpEle));
   }

}

======== hello.htm ========
<html>
<head>
<title> New Document </title>
<script>
function addElement() {
        app = document.getElementById("Hello");
        app.insertText("para");
}

</script>
</head>
<body>
<input type="button" onclick="addElement()" value="Fill"/>
<p id="para"></p>
<applet id="Hello" code="Hello.class" width="1" height="1"
mayscript="true" scriptable="true">
</applet>
</body>
</html>

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google