Applet lifecycle when out of focus - java

Does a Java Applet always execute its code even when it losts focus? I've to put this applet in a web page.
I'm tryng to understand this cause i've to develop an applet that listen to some hardware components through JavaPos. I have a callback method defined inside the applet and i'm not sure if it works even when users click on other page component.
Thanks

Does a Java Applet always execute its code even when it losts focus?
Yes, unless of course the applet code intentionally stops execution on loss of focus.

Related

Trapping Java applet cancel button

I have a Java applet that runs with no UI and sends XML back to the calling Javascript for processing to a database. I have the applet set up to do a callback once the applet is initialized using an Init override and the callback is a Javascript function that proceeds to do some work with another applet method.
If the user clicks the "No" button on Java security warning however, no applet code is ever run and the calling page waits forever for the callback to occur. Is there a way to trap the user declining the security warning in Javascript?
Please no questions on why I'm using an applet for this, it's a very complicated infrastructure (out of my control) which involves multiple web vendors and this is the only architecture I've found that meets all the other requirements.
About the best you can do is poll for the applet appearance in JS, and if it doesn't appear after a 'length of time', pop an alert to the user offering to redirect to help (or wait - if they are still looking over the details offered by the security dialog/pop-up).
Use applets, expect trouble. Use hidden applets, expect chaos..

My applet displays part of the screen behind it

So when I alt-tab between the applet and something else, may it be another window or just the desktop, the applet ends up looking like this when I come back to it:
This is the Embed gadget I use on the google site I host my applet on. Normally it would just be my applet, but it shows the stuff that I had recently alt-tabbed away from.
It also does this in Eclipse's applet viewer. Not just this applet, but every applet I've made (which is why I don't think it has anything to do with the code of this applet in particular).
Is this a problem related to the way I write my paint() method, or is it something else?

Restore focus to Java Applet when Browser/Tab gains focus

I have an applet running in a browser tab. When I switch to a different tab in the same browser, or ALT-TAB to another application entirely, the applet loses focus. When I return to the browser tab, the applet doesn't gain focus again. Is there a nice way to make this happen?
I assume it's a JavaScript change that's needed, not in the applet itself? Some onFocus handler perhaps? If it's relevant, our applet is created using an HTML <applet> tag.
I believe java has the requestFocus() method. It's in the Component class, so your JPanel or whatever you are using may be able to use this.
For the javascript part, this is what a quick googling reveals: http://www.raditha.com/java/javascript.php. I hope it helps you!

Detect java applet modal dialog in webbrowser control

We are hosting web applications in a .Net webbrowser control embedded in a winform.
When a java applet in a web application displays a modal dialog, only the applet area within the webapplication is deactivated. (The requirement is firefox-style modality).
Is there a way to detect that the applet in the webbrowser control displays a modal dialog? (alternatively, get a window handle, when a java applet dialog is opening?)
Use some JavaScript to directly call the Java method Window.getWindows() for an array of existing Window objects. (J)Frame objects and (J)Dialog objects all extend Window.
Note that, AFAIR, each applet gets a Frame to contain it. Because there will be more 'windows' on screen than just dialogs, you'll need to check the types.
Do that at an appropriate interval repeatedly from JS, and it should be possible to detect any dialogs produced by Java applets.
Alternately it might be easier to extend the applet and add some extra methods to make those same checks outlined above, then call a JavaScript to notify that there are dialogs opened.
Use sun.plugin2.main.client.ModalityHelper.installModalityListener(). This will signal modalityPopped and modalityPushed.
http://www.javasourcecode.org/html/open-source/jdk/jdk-6u23/sun/plugin2/main/client/ModalityHelper.html#installModalityListener%28sun.plugin2.main.client.ModalityInterface%29
Requires Java 6 and may only work on some specific platforms (scope yet unknown).

JavaFX Applet web-page refresh and close notifications

How do I detect when user closes(navigates away) or refreshes web page with JavaFX applet in it? I want to do some clean up in my code on those events.
Java Applet had some callback methods to do that, but how would I do it in JavaFX running in browser?
Two steps:
You may need to use a Javascript's window.onunload event to tell your JavaFX app to "close". If you do this, you can then
Add FX.addShutdownAction(myfunction); to your run() function. This will execute myfunction when your app is closed.
I don't have some complete code for you here, but I hope it's a start. You may not need to do step 1.

Categories

Resources