How to Use a java Applet through c#?
I would like to use a java applet which is on an htm开发者_运维知识库l file as ..
This java applet contains a textbox, and i want to access it as whenever I click a button in my c# app a certain txt appears there...
I have already embedded it with the use of webBrowser..
Any sample code, or suggestion?!..
Note: development under visual studio 2008 and I have the java applet source code..
The WebBrowser control isn't going to give you direct access to methods on a Java applet, AFAIK (you might be able to fudge your way through because I can't imagine that there isn't ActiveX involved, but I don't think that's the best answer).
Rather, what I would do is have a function in JavaScript that accesses the value of the textbox from the applet (assuming that the control in the applet exposes it publicly). It would assign the value to a property on the extern object exposed by the window object in JavaScript.
Then, you would create your own class which you would assign to the ObjectForScripting property on the WebBrowser control which exposes that property.
Finally, when you click your button, you would call the script (you can assign the function to your same object, if you want) which will assign the value, then get the value from the instance that you set to the ObjectForScripting property on the WebBrowser control.
There are other ways you can do this as well, you could have the JavaScript method write the text to a hidden element, then browse the DOM model to get the value, etc. etc.
In the end, whatever solution you have will more than likely involve a combination of DOM traversal and setting the ObjectForScripting property, as well as JavaScript in the HTML hosting the applet.
Another approach you can take is to create a UserControl or WebPart, which writes the HTML you need in the Render method. Here is a good link on the Render method (http://msdn.microsoft.com/en-us/library/system.web.ui.control.render.aspx).
We took this approach at one project I was on, where the <object>
and <param>
tags were created using custom configuration (Web.config and configuration sections) to render the proper HTML for a 3rd-party Applet.
精彩评论