Suppose we have an applet on a webpage and JQuery code in the same page, as well. How can we notify JQuery upon an Applet action, for instance a timer in the applet stops and a file system change occurs, and i want to make some process upon this file change in JQuery part as soon as the change occurs. Any suggestions / solutions? Thanks.
You can start with short article: Java - Javascript interaction.
And then see Java-to-Javascript Communication and
JavaScript to Java Communication (Scripting) for more info.
Related
I made an applet. It's starting when web page is loaded. But applet lost focus, when web page lost focus too and need to click on area of applet and then it gained focus.
I'm tried variants but it's not helpful
document.getElementById(appletId).focus();
document.getElementById(appletId).requestFocus();
How to set focus to applet in java script?
Ensure the applet element in the HTML declares scriptable=true
Add a public method to the applet that calls requestFocusInWindow().
Call that method using JavaScript.
Be sure to have the JS console open for run time debugging.
I have a cool bit of dojo running where I click a button and it brings a success message on the screen via JavaScript. Is it possible to issue a call to a server-side Groovy script (eg. foo.groovy) from within this JavaScript?
Not only do I want to show the cool success message, but I need to do some work in the background at that point also.
Here are some relevant links from the Dojo documentation:
Intro to AJAX and Dojo
Dojo.xhrGet() reference: sends a GET request to the server-side resource (which can be a Groovy script or anything else that resides on the server). The live examples on this page are currently broken, but I'm told this is being resolved.
Dojo.xhrPost() reference: sends a POST request. There are variants for PUT and DELETE too.
The answer was to use dojo's AJAX call system.
I am working for a developing firm and am doing a major redesign on a Web Application, which reloaded everything after each click, to make extensive use of Javascript, so it actually feels like a real Web application. One of the Features is to use a web-based Painter (think of MSPaint on the Web), which I embed on the Page on Demand. After the image is painted and uploaded, the Web-app then unloads the applet and proceeds to show the directory where the file was uploaded to.
This is where Trouble starts. It all works on IE and Safari, but not on Firefox 3.5 (3.0 works perfectly though). Firebug tells me that the expando property is missing.
The Web-app Tiparlo which I was working on before had a similar Problem (in fact, any manipulation done on an applet via jQuery is faulty) but solved that Problem by wrapping a div around and controlling (hide and show) the div instead of the applet. This, unfortunately isn't applicable on this Web-app, because the Applet has to be destroyed and not just hidden and shown, as it takes up too much resources to be run the entire time where it is not needed.
To make it short: Is it possible to make an Applet destroy itself via Javascript? Alternatively: Is there a workaround on the jQuery/expando/applet problem? I know that applet is deprecated in HTML 4.01 strict but changing it to object is not an option right now.
EDIT: I have added a Picture of Firefox + Firebug to show you the actual Error Message. Posting Code does no god, since it works flawless on every other Browser and is a Firefox 3.5 specific Problem. Here be pictures
Note: You can ignore the JS Bug coming from button.js.
You could always load the applet in a an iframe and just navigate away from the page where the applet is loaded. This will kill it.
Your other option if you want to call the destroy from javascript would be to put something like this in.
<script>
document.MyApplet.killApplet();
</script>
public void killApplet() {
AccessController.doPrivileged(new PrivilegedAction() {
public Void run() {
// kill the JVM System.exit(0); return null;
}
});
}
This is not a nice way to kill an applet but on newer browsers it does not throw a JS error, on older ones like IE6 it will throw a js error.
I would suggest that you create a class that monitors the applet to be killed. run the monitor as some sort of servlet and get javascript to post 'kill applet' commands when it needs to be killed.
I have a web application that processes events and audio received from a specialised microphone. The audio is processed by a Java applet that runs in the web page, but other events (microphone connected, microphone disconnected, microphone button pressed) are handled by an ActiveX object.
The ActiveX object traps these events and calls JavaScript code to handle them
<!-- Load the ActiveX control -->
<object id="PhilipsSpeechMikeCtrl" width="0" height="0" tabindex="-1"
classid="CLSID:AAA44754-CC81-4692-91AF-7064E58EB22A"
standby="Loading Philips SpeechMike component..."
type="application/x-oleobject">
</object>
<script type="text/javascript">
// This is Microsofts javascript way of trapping ActiveX object events.
function PhilipsSpeechMikeCtrl::SPMEventDeviceConnected(deviceID) {
// Call JavaScript code to handle the microphone connected event
}
function PhilipsSpeechMikeCtrl::SPMEventDeviceDisconnected(deviceID) {
// Call JavaScript code to handle the microphone disconnected event
}
function PhilipsSpeechMikeCtrl::SPMEventButton(deviceID, eventId) {
// Call JavaScript code to handle the microphone button pressed event
}
</script>
Of course a problem with this approach is that it's completely IE dependent. I would prefer to load the ActiveX object within the applet, trap the events there and handle the events either within the applet, or JavaScript code called from the applet. This should then enable me to run the app in any browser that supports applets.
I'm not entirely sure how to go about implementing the solution I've proposed above, any suggestions?
Update: I realise the solution I've proposed above would still be IE dependent, that's fine. My immediate goal is to support all browsers on Windows.
It has been suggested that instead of using ActiveX, I could use JNI (or JNA) to access the DLLs underlying the ActiveX object. However, I don't actually want to call the functions in the DLLs, I want the DLLs to call me, i.e. register an event handler.
Thanks,
Don
ActiveX are not supported by an another browser than IE, so there is no way for your application to support all browsers, even on Windows only.
An attempt (plugin) to port ActiveX under Firefox 1 was made, but wasn't really useful so as far as I know, there is today no "emulation" solution to your question.
Sorry...
(see here for Mozilla comments)
JACOB is supposed to let you call COM from Java. It looks like it supports events too.
You can probably access the dlls in the activeX component directly,
so you can write a jni wrapper that calls the native functions,
and then build a signed applet that can get permission to use jni.
Check this:
http://www.raditha.com/java/jni/
Ahh. You can do want you desire, but may have to eschew Javascript and instead leverage VBScript. It is about the ability to send "events" between two components.
You can use use JavaScript to directly call public methods in the applet or access public variables. JavaScript treats the embedded applet as an object. In the applet tag give the applet a name id.
Consider the example below where the applet has a method public void myMethodInMyApplet();
The HTML page would look something like :
<APPLET CODE="MyApplet.class"
width=200 height=200
name=counter ID=counter>
</APPLET>
<script type="text/javascript">
// This is Microsofts javascript way of trapping ActiveX object events.
function PhilipsSpeechMikeCtrl::SPMEventDeviceConnected(deviceID) {
document.applets[0].myMethodInMyApplet();
}
</script>
Wouldn't that still be Windows- or even IE-dependent, given that Java applets are executed on the client side? Just wondering...
You will obviously have to pass the events twice if you want them to end up in JavaScript.
There is a version of SWT that can be used in applets and can embed ActiveX controls. There are also commercial libraries like Coroutine who can do this as well (and are smaller in jar size). Someone else mentioned JACOB here, which would be another choice.
So, use any of these components to wrap your ActiveX control. These libraries will call a Java method when a registered event occurs.
To pass events from Java to JavaScript, you can use the netscape.javascript.JSObject class which is supported by all major browsers.
If you have the source code for the COM component, it might be a good idea to rewrite it to use JNI, as COM wrappers use up a lot of resources (which is especially important in applets), and most probably there is also some overhead inside the COM component for COM interop.
is activexobjects always hitting the acivex sites like activex.microsoft.com
Consider the most excellent wordle tag cloud generator:
http://www.wordle.net/create
Entering text into the "textform" textarea and clicking the go button starts up the wordle java applet on that page. No traffic goes back to the server.
How can I cause this to happen programmatically? No hack too cheap!!
background for this question:
"tag cloud" generators?
If you mean starting it programmatically from a browser page, you can use the same type of JavaScript that that page uses, which calls the function Wordle.t() to start the applet.
If you want to call it from a Java program, you can download the Wordle.class or jar file yourself, and call the functions directly.
I'm the creator of Wordle.
In case anyone finds this page in the future, I thought it would be useful to explain that Wordle invokes its applet by constructing an applet tag with a huge <param> containing a sanitized version of whatever text you pasted in. It is the cheapest hack imaginable.