java不锁屏幕,使用Java锁定屏幕

Basically i just need to create an application (with sort of user access) which first screen is a fullscreen window that cannot be minimized or closed without entering valid username and password. Something like windows screensaver. Can it be done? What libraries should i look into? This is all i need, if my question is incomplete or unclear, feel free to ask!

解决方案

Once, I wrote something in Java, out of which you can't escape. Really impossible. It is for Windows. Here you go:

import java.awt.Robot;

import javax.swing.JFrame;

public class WindowsSecurity implements Runnable

{

private JFrame frame;

private boolean running;

public WindowsSecurity(JFrame yourFrame)

{

this.frame = yourFrame;

new Thread(this).start();

}

public void stop()

{

this.running = false;

}

public void run() {

try {

this.terminal.getParentFrame().setAlwaysOnTop(true);

this.terminal.getParentFrame().setDefaultCloseOperation(0);

kill("explorer.exe"); // Kill explorer

Robot robot = new Robot();

int i = 0;

while (running) {

sleep(30L);

focus();

releaseKeys(robot);

sleep(15L);

focus();

if (i++ % 10 == 0) {

kill("taskmgr.exe");

}

focus();

releaseKeys(robot);

}

Runtime.getRuntime().exec("explorer.exe"); // Restart explorer

} catch (Exception e) {

}

}

private void releaseKeys(Robot robot) {

robot.keyRelease(17);

robot.keyRelease(18);

robot.keyRelease(127);

robot.keyRelease(524);

robot.keyRelease(9);

}

private void sleep(long millis) {

try {

Thread.sleep(millis);

} catch (Exception e) {

}

}

private void kill(String string) {

try {

Runtime.getRuntime().exec("taskkill /F /IM " + string).waitFor();

} catch (Exception e) {

}

}

private void focus() {

this.frame.grabFocus();

this.frame.requestFocus();

}

}

Background of this code: I wrote some kind of fake terminal in which I could let appear everything what I wanted. Eg, the stupid Windows messages like: "Keyboard not found, press any key to continue". I used it as a joke on school. Fire up this app and leave the room, it would log out the Windows account automatically after one minute. But I hadn't thought that there would be a teacher that used Ctrl-Alt-Del to kill my application. He left a message in my personal documents in which he wrote what he did and ended his message with "I've beaten you, haha I'm evil". So, I wanted to go in competition with him. And then wrote this code. He tried more than five times in school to escape from the app, but he couldn't (I can't as well :D). Of course he could turn off the machine or log out. But the target was to access my personal documents.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值