JavaFX Applet web-page refresh and close notifications - java

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.

Related

Start Android Emulator and perform UI script

This is my first question in this amazing service.
So this is what i want to do:
I want to start Android Emulator, perform few actions with UI (fill login/password form and click Login button) and then leave it running.
I wrote some automatic tests with Robotium framework before and know how to make a TEST that running an asserting something. The problem is that test will terminate soon or later. But i need to log in through UI and leave emulator running like some kind of homemade system service.
What would you suggest to solve this problem?
Thanks.

Applet lifecycle when out of focus

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.

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..

Run Java function on page change in Phonegap

I've got an Android Phonegap app that takes a website and injects a few new libraries and stylesheets (zeptojs angularjs etc.)
In my specific case I cannot simply re-write the code to JavaScript on the page (as I'm not the one in charge of the page's scripts), instead I'd like to use the Java function sendJavascript(), and run it from a Java timer object.
But no matter how I call sendJavascript it never seems to do anything.
eg:
myActivity.this.sendJavascript("javascript: alert(1)");
But alert(1) never actually fires
To call the java function from javascript you have to write a phone gap plugin. Then in the change page handler you call the javascript function from the plugin.
Can you give more details on what the alert is all about? Does it relate to the java function that you want to call previously, or is something that you want to notify from the native side?

Block all other input to an application and control it from a wrapper in Java

I have a windows application which has a complex GUI that I would like to hide from users. In order to do this, I would like to create a wrapper with an extremely simple interface that overlays this application and automates a number of actions when a user clicks a single button on the wrapper. (I hope "wrapper" is the proper term.) Is it possible to use Java to block input to the underlying application so that users cannot inadvertently mess up the automation? How would I go about this? Also, how can I automate key presses and clicks to the application without hijacking the mouse? Is this possible in Java?
I have looked at java.awt.Robot, but it appears to hijack the mouse.
I have also looked at AutoIT, but it too hijacks the mouse and does not integrate with Java.
Neither of these options seem powerful enough for what I need, but I do not know how else to proceed.
I recommend that automation via the GUI only as the last resort if you really have no other alternative.
If there is an API that your application exposes, I would try to use that. For example, if the GUI is implemented in one DLL and the logic in another, then you can use JNA to load your application logic DLL and invoke the application functions directly from java. Even better would be if your application exposes a COM/OLE interface - there are plenty of Java<>COM briges, that will alow you to call this interface directly, e.g. Jacob.
If you really have no choice but to automate via the GUI, then here's how to go about doing that:
Use JNA to access the windows shell API. You can then use ShellExecute to launch your wrapped application. Specifically, passing SW_HIDE as the window mode should help ensure that the application does not appear.
Use JNA to access the windows API FindWindow to find your application window. You can also make it invisible using the ShowWindow API, just in case step 1 did not work (not all applications are written to use the nCmdShow parameter.)
You can now post messages to the application window using PostMessage. You can send keystrokes and mouse events using windows messages. E.g. See WM_KEYUP, WM_LBUTTONDOWN.
Because the wrapped application window is made invisible, you don't need to "block" that application, The user simply cannot access it's GUI. But you can still programmatically send input to it.

Categories

Resources