在我的swing应用程序上设置超时 [英] Setting a timeout on my swing application

查看:107
本文介绍了在我的swing应用程序上设置超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java swing应用程序,其中包含多个面板并在它们之间进行转换(按钮,输入...). 我现在想要的是为整个应用程序设置一个超时(这将使用户在我的软件上注销),然后将该用户重新带到另一个JPanel(我不需要那部分帮助).

I have a Java swing application with several panel and transitions between them (button, inputs ...). What I want now is to set a timeout for my whole application (that will logout the user on my software), and bring back the user to another JPanel (I don't need help for that part).

经过一番研究,我发现有些东西似乎起作用(未完全实现atm),我将Key,MouseMotion和MouseWheel侦听器添加到所有我的swing元素中,并为任何用户操作重新加载计时器.

After some research I have found something that seems to work (not fully implemented atm), I'm adding Key, MouseMotion and MouseWheel listener to ALL my swing elements and reloading my timer for any user action.

我想知道是否有任何内置函数可以处理这种情况或更好的方法.谢谢

I wanted to know if there is any built-in function that can handle such a situation or a nicer way to do it. Thanks

推荐答案

我将Key,MouseMotion和MouseWheel侦听器添加到所有我的swing元素

I'm adding Key, MouseMotion and MouseWheel listener to ALL my swing elements

您可以签出应用程序不活动,该操作使用AWTEventListener,因此您无需为所有组件执行此操作.

You can check out Application Inactivity which does this using an AWTEventListener so you don't need to do it for all your components.

您为监听器提供了Action,供您在闲置一段时间后调用.

You provide the listener with an Action to invoke after your period of inactivity.

这篇关于在我的swing应用程序上设置超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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