简体   繁体   English

你能创建一个无法解决的,不可解决的Java应用程序吗?

[英]Can you make an uncloseable, unleavable, Java application?

Is there a way to make sure that a user cannot close or leave my Swing application? 有没有办法确保用户无法关闭或离开我的Swing应用程序? 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. 我试图将其全屏显示,但你仍然可以使用Alt-Tab远离它 - 此外,当你决定使用JOptionPane的对话框时,这不会很好。

So, is there any way to make a user use only this one Java program on a device? 那么,有没有办法让用户在设备上只使用这一个Java程序?

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. 该应用程序应该被“嵌入”到手持设备(在Windows下运行),因此设备的用户将使用它,因为我们打算使用它 - 例如,他们不会玩Freecells或做更糟糕的是,而不是做实际的工作。 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! 他们被锁定得很好,你不能只关闭他们的华丽GUI并进入Windows桌面!

Okay @Daniel showed you how to make a Java app un-closeable (+1 to him) by calling: 好的@Daniel通过调用以下方式向您展示了如何使Java应用程序不可关闭(+1给他)

JFrame#setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

on the JFrame instance. JFrame实例上。

To make sure you cant leave it ie by pressing CTRL + ALT + DEL and ALT + TAB etc you may want to do this (applies to windows only): 为了确保你不能离开它,即按CTRL + ALT + DELALT + TAB等你可能想要这样做(仅适用于Windows):

1) Disable TaskManager/ CTRL + ALT + DEL by: 1)通过以下方式禁用TaskManager / CTRL + ALT + DEL

  • Setting registry key: 设置注册表项:

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

    via reg script or cmd.exe. 通过reg脚本或cmd.exe。

2) To disable all shortcuts together like ALT + TAB etc see here (Download/use the *.reg script and execute it via cmd ). 2)要禁用所有快捷方式,如ALT + TAB等,请参阅此处 (下载/使用*.reg脚本并通过cmd执行)。

Uncloseable yes, you can use setDefaultCloseOperation(); 不可理解的是,你可以使用setDefaultCloseOperation(); and pass it JFrame.DO_NOTHING_ON_CLOSE 并传递给它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);
    }
}

We do something similar with a POS application, but we cheat a little bit. 我们用POS应用程序做类似的事情,但是我们做了一些欺骗。 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. 最后,我们创建了一个Windows服务(是的,我们在Windows上运行),它会在关闭后自动进行RESTARTS。 So, you can see the Windows desktop (we removed the icons) for a split second, but then the app pops up again. 因此,您可以看到Windows桌面(我们删除了图标)一瞬间,然后再次弹出应用程序。 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. 这样做的好处是我们可以从Intranet远程更新JAR文件,所有用户需要做的是按下一个关闭系统的按钮,它会自动重启并更新。 We wanted to use WebStart, but had problems integrating it with our wrapper. 我们想使用WebStart,但是在将它与我们的包装器集成时遇到了问题。

The wrapper itself is a Python application that just starts the JVM and application, compiled to an EXE. 包装器本身是一个Python应用程序,它只启动JVM和应用程序,编译为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. 为应用程序提供启动凭据管理员权限,以及用户只是一个普通帐户,也可以处理讨厌的'alt-ctrl-del'用户。 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. 如果你不想写自己的包装,请给http://wrapper.tanukisoftware.com/doc/english/product-overview.html一个旋转,它看起来像一个出色的产品。

You can catch pretty much any keystrokes you like (and have them ignored) in your app, so Alt-Tab can be fixed. 您可以在应用程序中捕获您喜欢的任何击键(并忽略它们),因此可以修复Alt-Tab。 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. 应用程序永远不会 (ish)处理自身的一个组合键是Ctrl + Alt + Delete,出于安全原因,它在许多操作系统中被挂接到内核中。 As a side note: this is why many login screens ask you to hit C+A+D before entering your username and password. 作为旁注:这就是为什么许多登录屏幕要求您在输入用户名和密码之前点击C + A + D.

You can make a maximized window that can't be unmaximized or closed. 您可以创建一个无法最大化或关闭的最大化窗口。 You'd also have to trap certain keystrokes such as CTRL+SHIFT+ESCAPE, ALT+TAB, WIN+[anything], various Fn keys, and you'd have to do something to prevent CTRL+ALT+DELETE from working (Either from showing the task manager or from bringing up the blue options screen in windows vista or 7. 您还必须捕获某些击键,例如CTRL + SHIFT + ESCAPE,ALT + TAB,WIN + [任何],各种Fn键,并且您必须做一些事情来阻止CTRL + ALT + DELETE工作(来自显示任务管理器或在Windows Vista或7中显示蓝色选项屏幕。

I believe there are windows API calls that can change the behavior of CTRL+ALT+DELETE somehow but have no idea what they are. 我相信有一些Windows API调用可以改变CTRL + ALT + DELETE的行为,但不知道它们是什么。 A good place to investigate would be Sysinternals Process Explorer, which has the functionality to replace the task manager. 调查的好地方是Sysinternals Process Explorer,它具有替换任务管理器的功能。 Figure out how it does this, then replicate it. 弄清楚它是如何做到的,然后复制它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM