问题描述
我需要一个 1-10 秒的可变倒数计时器,可以停止和重新启动.用于此目的的一组好的 UI 元素是什么?我需要一些直观的东西,它使用相当少量的屏幕空间,与普通大小的 JButton 相当.发条厨房鸡蛋计时器将是最好的物理类比:
I need a variable countdown timer for between 1-10 seconds, that can be stopped and restarted. What's a good set of UI elements to use for this? I need something intuitive that uses a fairly small amount of screen real estate, comparable to a normal-sized JButton. A windup kitchen egg timer would be the best physical analogy:
注意:我知道如何实现计时器并重新启动它们,我只需要弄清楚要使用哪些 UI 元素.
NOTE: I know how to implement timers and restart them, I just need to figure out what UI elements to use.
注意 2:我需要一个变量倒数计时器.如果用户想要 1 秒,我想要一个 1 秒计时器.如果用户想要一个 8.2 秒的计时器,我想要一个 8.2 秒的计时器.上面的厨房定时器很简单,用户只要把它调到一定的量就可以了.
NOTE 2: I need a variable countdown timer. If the user wants 1 second, I want a 1 second timer. If the user wants an 8.2 second timer, I want an 8.2 second timer. The kitchen timer above is simple, the user just turns it to a certain amount and lets it go.
推荐答案
为什么不使用 JProgressBar
开始满"并随着时间的减少而清空?您将剩余时间(以秒为单位)叠加在栏上,从而避免使用额外的屏幕空间.
Why not use a JProgressBar
that starts off "full" and empties as the time decreases? You overlay the remaining time in seconds over the bar, therefore avoiding using additional screen real estate.
这篇关于Swing:倒数计时器的 UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!