如何在 Swing 中拦截 Windows 启动事件 [英] How to intercept Windows startup event in Swing

查看:34
本文介绍了如何在 Swing 中拦截 Windows 启动事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个带有几个标签的 JFrame.我需要显示一次带有欢迎用户"消息的 JOptionPane.如果在重新启动 Windows 之前重新打开框架,JOptionPane 不应出现,但如果 Windows 重新启动,JOptionPane 应再次出现.

I created a JFrame with a few labels. I need to display a JOptionPane with the message "welcome user" once. If the frame is re-opened before rebooting Windows, the JOptionPane should not appear, but if Windows is rebooted, the JOptionPane should appear again.

自上次运行应用程序以来,如何检测系统是否已重新启动?

How am I able to detect whether the system has been rebooted, since the last time my application ran?

推荐答案

所以,正如@Kayaman 提到的,Java 中没有 isRebooted() 方法......但你可以制作一个.

So, as @Kayaman mentioned, there isn't an isRebooted() method in Java... but you can make one.

假设您在 Windows 平台上工作(您需要为其他操作系统实现单独的版本),您可以查询 系统事件日志.把所有的东西放在那里,我认为它会包括一个登录"事件,所以你需要做的就是找到一种方法来查找上次登录"时间,看看它自上次以来是否发生了变化上次检查.

Assuming you are working on Windows platforms (you would need to implement a separate version for other OSes), you could query the system event log. With all the stuff that gets put in there I reckon it would include an event for "logged in", so all you need to do is find a way to look up the last "logged in" time and see if it has changed since the last time you checked.

访问事件日志是特定于 Windows 的技巧,因此不会出现在本机 java api 中,但是有一个关于如何从 Java 访问事件日志,您可以将其用作基础.

Accessing the event log is a windows specific trick, and so won't be in the native java api, however there is a question on how to access the event log from Java which you could use as a base.

这篇关于如何在 Swing 中拦截 Windows 启动事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆