File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes Applet to Javascript communication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Applet to Javascript communication" Watch "Applet to Javascript communication" New topic
Author

Applet to Javascript communication

Allen Bandela
Ranch Hand

Joined: Feb 16, 2006
Posts: 128

Hi:
I would like to know how I can pass data from my applet class to my java script html page. is it possible? i could call a method in my applet from the javascript, but is the reverse possible? Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41621
    
  55
Welcome to JavaRanch.

Yes, that's possible. The technology you're loooking for is called LiveConnect, and the Applet FAQ has more detail on how it works.


Ping & DNS - my free Android networking tools app
Allen Bandela
Ranch Hand

Joined: Feb 16, 2006
Posts: 128

Thanks Dittmer.

I have a problem and I am confused as of how I should go about it.

I have to put up a textfield, a button and a list on my webpage. Should I do that with my applet class, implementing actionlistner interface for the button, or should I do it in java script and pass the text field data to my applet ( by getparameter()) for furthur processing using getparamter(). Which is better?

Being inclined to using an applet, is there a way I can put my text fields at the position I want them on my webpage by using the repaint() method?

Thank you
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41621
    
  55
I'm not sure what you're trying to do, or whether a JavaScript/applet hybrid is the best way to go about it - why are you inclined to use an applet?

getParameter has nothing to do with LiveConnect. It picks up parameters from the applet tag, which can't be changed later.

paint/repaint draws in the applet. It can't position elements on the web page itself.
Allen Bandela
Ranch Hand

Joined: Feb 16, 2006
Posts: 128

What I'm really trying to do is implement a search engine for my website. (I am not implementing an actual search engine though, only an index of keywords matched to certain parts of my website. )
I want to display a typical search box and a list to display the results. I wanted to do it in an applet, because I don't know about liveconnect and I have to use applet to parse the search keywords. I'm trying to figure out how I can use layout managers, maybe, to display my user interface at a particular position on my webpage.

Like if I wanted my user interface of the applet on the upper right, so as not to disturb the rest of the webpage, can I do it?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41621
    
  55
You can position your applet wherever you want it, but that's an HTML issue. Wrap the applet tag inside a DIV, which you can style and position to your hearts content using CSS. Layout managers control how the various GUI elements of an applet are positioned inside the applet. An applet has no control over where it gets placed on a web page.
 
jQuery in Action, 2nd edition
 
subject: Applet to Javascript communication