Talking to applets with JavaScript
I got asked recently "how do you get JavaScript to access the methods of a Java applet?"
Seeing as though, at the time, I was "learning" Java and always hate to have to say "I don't know" - I set about finding out. It turns out it isn't half as hard as you might imagine.
Before we start, let's look at an example. The yellow box below is a simple applet that contains just a label and a text box. Use the select box (HTML) below it to update your favourite colour.
My favourite colour is:
How does this work? Technically I think it is something to do with a Netscape invention called LiveConnect, but I won't bore you with that.
The first thing to do is create a public method in your applet that performs the actions you require. The applet above uses this code:
public void setMessageText(String message) {
txtMessage.setText( "You chose: " + message.toUpperCase() );
}
That is the hard part. Yep, that's it! All you need to do now is to create a JavaScript call to this method via the applet object. Like this:
document.applets[0].setMessageText('This text came from JavaScript');
The only other thing you need to do is add the "MAYSRIPT" attribute to the applet's tags so that is allows JavaScript to tell it what to do.
Now you may well be thinking - "What use is that!?" Wait, the possibilities are almost endless. For a start, applets can use CORBA/IIOP connections to the server to go and fetch data, not only from Domino servers. No more need to submit the document to get data from the server ;-)
All you need to do now is get up to scratch with Java applets so that you can start creating your own applets. I've attached the source file (.java) for you take a look at, but this is VERY basic. For more help you best bet is to do a search on the usual sites.
Other sources:
http://www.alphaworks.ibm.com/
http://www.looseleaf.net/Looseleaf/Forum.nsf
http://java.sun.com
http://www.notes.net/
from lotus script
Hi, if you want to use with an agent made in lotus script you should do this :
1) copy your field from the agent to the form. ex: Call docTemp.CopyAllItems(docStat) docStat.Form = "fHistogramme" Call workspace.EditDocument(False, docStat, True)
2) add the applet on the form (create menu) Note : the applet must have to get the parameters values in the init methot. Ex: public void init() { ... String str_temp; str_temp = getParameter("text"); ....
3) Add the parameters and the values (fields) in lotus at the applet's parameter values. Note : the name of the parameter must be the same in the applet. (here, the parameter's name in lotus is "text")
Philippe Desrochers
Reply
lotus script
I am a student in washington computer Accadmy doing computer hard ware engineering.I need a lecture note in Lotus script and Lotus administrator. Thank you Emmanuel T.Kamara
Reply
Applet JavaScript LiveConnect
Hi Eventhough I have implemented these sort of functionality, this seems to be too nice. Especially most of them won't believe You could transfer /get values between Applet and JavaScript without submitting a JSP/Html page. this pretty Cool .
More than that this site seems to be pretty Nice that delevers technology.
Why Can't You Bring up an applet ie that use a import java.FileChooser.* that does the file Upload ? that could help people to do a Buld UpLoad ?
Great Site !
Thanks Jackson
Reply
Re: Applet JavaScript LiveConnect
If u use java.io.FileChooser and get files to applet then how u going to upload those file to document??
Any idea..
Reply
How do I send Values from Applet to JavaScript
Hi
Sorry to ask How do I send Values from Applet to JavaScript
COuld some one help me
Thanks James
Reply
Re: How do I send Values from Applet to JavaScript
Don't be sorry to ask just be sorry no to have searched the site more thoroughly ;o)
The article you are looking for [<a href="unid/DOMM-4UTFCP?OpenDocument">is here</a>]...
Jake -codestore.net
Reply
Misspell
"The only other thing you need to do is add the "MAYSRIPT" attribute to the applet's tags so that is allows JavaScript to tell it what to do. "
MAYSRIPT should be MAYSCRIPT. Good article though :)
Reply
neat trick
didn't know this was possible.. thanks
Reply
Applet in Notes Client
How can I make an applet load in the Notes Client?
Reply
Applet doesn't work on Firefox
Hi Jake,
Here I have a problem. Your applet doesn't work on Firefox, but works on IE. Do you have any idea of what happend?
Thanks a lot
It rise this error (horrible):
*****************************************************
cargar: clase SimpleApplet.class no encontrada.
java.lang.ClassNotFoundException: SimpleApplet.class
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: open HTTP connection failed:http://www.codestore.net/store.nsf/area/area/67CB4D15E50B305C862569FC003FBD7C/$FILE/SimpleApplet/class.class
at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 7 more
Excepción: java.lang.ClassNotFoundException: SimpleApplet.class
Reply
Using JavaScript How to check whether an applet is loaded or not???
thanks in advance
Reply
how can i execute the javaapplets using javascripts. In a browser i have javaapplet and i need to execute this using javascripts.. how can i do this??
any suggestions or sample code for javascripts to run javaapplets
Reply
How to execute the javaapplets using javascripts:
http://www.rgagnon.com/examples/InJava.html
Reply