Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you make an uncloseable, unleavable, Java application?

Tags:

java

swing

jframe

Is there a way to make sure that a user cannot close or leave my Swing application? I've tried to make it fullscreen, but you can still Alt-Tab away from it—and besides, that doesn't work well when you decide to use JOptionPane's dialogs.

So, is there any way to make a user use only this one Java program on a device?

Edit: Some people wonder about the purpose. The application is supposed to be sorta "embedded" into the handheld device (which runs under Windows), so the users of the device will use it as we intend it to be used—for example, that they won't play Freecells or do something worse instead of doing the actual work. Have you seen ticketing kiosks? They are locked down pretty well, you can't just close their big flashy GUI and get to the Windows desktop!

like image 409
Joker_vD Avatar asked Oct 08 '12 13:10

Joker_vD


4 Answers

Okay @Daniel showed you how to make a Java app un-closeable (+1 to him) by calling:

JFrame#setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

on the JFrame instance.

To make sure you cant leave it i.e by pressing CTRL+ALT+DEL and ALT+TAB etc you may want to do this (applies to windows only):

1) Disable TaskManager/CTRL+ALT+DEL by:

  • Setting registry key:

    HKCU/Software/Microsoft/Windows/CurrentVersion/Policies/System/DisableTaskMgr = 1

    via reg script or cmd.exe.

2) To disable all shortcuts together like ALT+TAB etc see here (Download/use the *.reg script and execute it via cmd).

like image 82
David Kroukamp Avatar answered Nov 12 '22 22:11

David Kroukamp


Uncloseable yes, you can use setDefaultCloseOperation(); and pass it JFrame.DO_NOTHING_ON_CLOSE

Example:

import javax.swing.*;
import java.awt.*;

class app extends JFrame {
    app(String title, int height, int width)
    {
        super (title);
        setSize(width, height);
        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        setVisible(true);
    }

}
class program {
    public static void main(String[] args) {
        app myApp = new app("Hello", 350, 750);
    }
}
like image 45
dsgriffin Avatar answered Nov 12 '22 22:11

dsgriffin


We do something similar with a POS application, but we cheat a little bit. While making use of Full Screen helps a lot, we found users could STILL exit the application.

In the end, we created a Windows Service (yes, we run on Windows) that automatically RESTARTS as soon as it's closed. So, you can see the Windows desktop (we removed the icons) for a split second, but then the app pops up again. The benefit of this is also that we can update the JAR file remotely, from the intranet, and all the users need to do is push a button that closes the system, it restarts automatically and is updated. We wanted to use WebStart, but had problems integrating it with our wrapper.

The wrapper itself is a Python application that just starts the JVM and application, compiled to an EXE. Simple, but effective.

The net effect is a closable application that will automatically start itself again. Good enough for our use where we need to user to be able to do one thing and one thing only. Giving the startup credentials for the application Admin privileges, and the users just a normal account, took care of the pesky 'alt-ctrl-del' users as well. You can't kill a process that's got higher access rights than yourself.

If you don't feel like writing your own wrapper, give http://wrapper.tanukisoftware.com/doc/english/product-overview.html a whirl, it looks like a brilliant product.

like image 34
Ewald Avatar answered Nov 12 '22 21:11

Ewald


You can catch pretty much any keystrokes you like (and have them ignored) in your app, so Alt-Tab can be fixed. The one key combination that an application can never (ish) handle itself, is the Ctrl+Alt+Delete, which is hooked into the kernel in many operating systems for security reasons. As a side note: this is why many login screens ask you to hit C+A+D before entering your username and password.

like image 1
lynks Avatar answered Nov 12 '22 20:11

lynks