Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the Anti-shaking function of Button in JavaFx

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces JavaFx how to achieve button anti-shake function, has a certain reference value, interested friends can refer to, I hope you have a lot of harvest after reading this article, let Xiaobian take you to understand.

JavaFX

JavaFX is an open source, next-generation client application platform for Java-based desktop, mobile, and embedded systems. It is the result of a concerted effort by many individuals and companies to provide a modern, efficient, and fully functional toolkit for developing rich client applications.

javafx Chinese website

Android platform APP, generally there is a need to set the button anti-shake (that is, in a short period of time can not be clicked multiple times), I want to JavaFx project is also to achieve anti-shake function, is to study the next

realization principle

Before clicking the button, record the current click time. When the button is clicked next time, calculate with the previously recorded click time and judge whether the interval time between the two is greater than the set condition value.

Here the idea is not difficult, mainly click on the history of time how to record? there are several ways

Use Map storage (too many buttons take up a lot of resources)

Use one of the useless fields provided by the control object for storage

In Android, you can save information using tags in View.

In JavaFx, all controls have userData fields, with this, we can store time

Implementation code Kotlin version:

kotlin version I am using the extension method, the BUtton class has been extended, do not understand the extension method can check the information, simply put, that is, to the Button class added a method

//Note Button is fun Button of javafx package.isFastClick(): Boolean { val lastClickTime = userData as Long? val currentTime = System.currentTimeMillis() userData = currentTime //Here I set it to invalid multiple clicks within 1s, which can be adjusted as needed if (lastClickTime != null && currentTime - lastClickTime

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report