How to prevent user close my application? (Linux Touchscreen apps) - java

I would like to have an application running in a linux box with a touchscreen monitor.
I don't want to use Flash player (with full window size), so my question is, what I should use instead of a Flash Player?
This box is gonna be in a place with a lot of kids, so they can close the application and shutdown the machine XD.
I'm not a Sr. Java developer, so I don't know if theres something over there to block the 'close window' feature in an java application.
Thanks in advance!

Assuming you're using swing, you could use Frame.setUndecorated(true) and maximize it. There is also the option of exclusive full screen mode. From there, you'll have to unbind any global keys that map to window-exiters/taskmanagers/other-utils.
You may also want a watcher/spawner script setup to make sure your app stays up. I bet there is a more elegant way to do this but most window managers try to avoid an app doing this due to malicious possibilities.

Related

how to create a background process , it will disable the physical volume buttons when running

My boss ask me to develop an app which have to be always on the user screen. I have to disable the three Android native buttons (back, home and history buttons).
How can I do that ? Create a custom launcher ?
Thanks.
In general you can't really do the things you mentioned above, at least there are no official supported APIs.
However, there can be legitimate use cases where one would benefit from this kind of applications, and Android provides something for this.
Have a look into Lock Task Mode and ScreenPinning.

Kiosk mode for Linux Java Swing application

How can I disable OS-level keyboard shortcuts (e.g. Alt-Tab, Ctrl-Alt-Left/Right, etc.) on a [Ubuntu] Linux machine? I'm developing a full-screen Java Swing app and don't want the user to be able to task switch away from the program arbitrarily. It's not enough to toggle the "always on top" flag; users mustn't be allowed to switch workspaces, migrate focus or any other such things. The machine must function normally before and after the application is executed. Google says that this will require JNI or JNA but I'm looking for a bit more hand-holding.
There's no point in trying to do this in your application because any of these changes are going to need to be handled by X11 and/or the window manager since those are what respond to the commands. Assuming that you have control of the platform, choose a window manager which supports a kiosk mode. Then use the window manager's settings to start your application and enter kiosk mode.
Options for window managers which can do this include KDE or twm-kiosk.
(And if you don't have control of the platform, you're not likely to be able to have your application intercept things like ctrl-alt-backspace anyway.)
Edit:
In response to a scaled-down version of the question in which he's willing to let things like ctl-alt-backspace go and just wants most of the keys including alt-tab or other similar application switching key combinations, the following should work:
You should be able to do this using XLib's XGrabKeyboard method through JNI. This Java/XLib JNI keypress capture tutorial should be a good starting point. However, it uses XGrabKey which just passively listens for keys and does not prevent other applications from receiving them. You'll instead want to use XGrabKeyboard which actively snags all of the normal keyboard events (which, if the premise of this StackOverflow question is correct, includes the task switching keys).
Note that as a side-effect, key capture in Swing will also probably stop working because your Swing windows are going to be separate from the window you create in C. As such, you will probably have to use your JNI interface to get key presses to your program when needed. (Although I would definitely advise testing it first before writing the code.) You might be able to avoid this if you can get the window using Java AWT Native Interface to get the window ID. (Note that Swing is built on top of AWT, so this will work for Swing.) However, I'm not sure how to do this. It looks like you might be able to navigate the window tree by getting the root window from the Display and going from there to find your Window, but it's all kind of weird. It would be nice if the AWT NI just told you the window ID, but it doesn't look like it does that.
As this warning Reminder: XGrabKeyboard is not a security interface notes, this doesn't make it impossible for other programs to see the keys, but it seems likely that window managers will not be using XQueryKeyMap so it is likely to prevent task switching.

Flashing taskbar using Java (a la pidgin || MSN)

I'm looking for a push in the right direction. I have a simple chat program, written totally in Java, and am looking for a way to get the Taskbar icons to flash. Preferably in a manner similar to Pidgin, or MSN.
I'm hoping for a platform independent solution, as there are both Linux and Windows users, and preferably totally in Java.
There is unfortunately no way to do this in the standard Swing API. But you could work around it in several ways:
Flash the icon and title of the window (set a timer and change them whenever it fires).
Request focus, then immediately make the window invisible; reverse the process at your preferred interval.
Both techniques are demonstrated in this forums.sun.com thread.
Alternatively, instead of flashing, you could display a message in the system tray using TrayIcon.displayMessage(); that may or may not suit you better, but beware that it may not work cross-platform.

Java desktop app: How to maximize tray application when hotkey pressed?

I need to write a program that, when minimized, lives in the System Tray, and I'll use Java 6's SystemTray API to do that.
How can I make that application comes to the foreground when the user presses some hotkey?
For example, the app is running but minimized. When the user presses CTRL-SHIFT-Y or something (or, like Google Desktop's search, CTRL twice) and the application is maximized.
EDIT: I know about how to bring a Java window to the foreground. I'm asking more specifically about how to make a running Java app listen for a hotkey.
You're going to need to resort to JNI, check out an example.
Here's another nice example from Sun's forums.
You can use the following SWT extension library to create a keyboard hook that can listen for your hot key - http://feeling.sourceforge.net/
note, that this is windows only (but that may not be a problem for you).

Recommended technology choice for desktop application

I am creating an application that is essentially a financial alerts site. I am a basic level Java programmer, and I have created some of the logic for alerts in Java.
I want to be able to have pop-ups appear on the desktop whenever something "interesting" happens (interesting depends on %change, liquidity and a few other simple factors).
What is the best combo of technology to implement something like this?
I would use the java.awt.SystemTray in Java SE 6. It's cross-platform and pretty easy to use.
Although some people hate the balloon notifications in Windows, they're the least obtrusive popups, since they can be ignored by the user or easily dismissed. Most importantly, they can't be missed by the user who has been away from the computer, because balloons (at least in Windows XP/Vista) use system idle timers to determine when's the right time to disappear.
Some prefer more traditional toast notifications, similar to those shown by Outlook - they show up and slowly fade out, giving the user some time to interact with them if needed.
I had the same problem and finally solved it using an undecorated, alwaysOnTop window.
And thanks to this blog entry I found the TimingFramework, and now it even is translucent, fades in and out, goes 100% opaque on mouse over etc. In conjunction with the SystemTray and TrayIcon the behavior is nearly as that of Outlook.
Oh, I have to note, that other than the second link, I do the fading out with
AWTUtilities.setWindowOpacity(window, op);
You could write a java program that resides in the system tray, but I am not sure if there are cross platform compatible ways to do this. maybe you have to use a platform specific library for Win, Mac, Linux, ...
I'd just create a message window and animate it. Then add SystemTray support and voila, you're done.
In Delphi you can do that pretty quickly, but you can't easily reuse your java logic
You can just run you program in "silent" mode, without creating any windows by default, maybe just a little icon in the taskbar which when double-clicked will open a settings window. The program will be running in the background and creating windows with the set focus whenever an event happens.
But in my opinion, a slide window or at least a balloon tooltip is a better idea.

Categories