Java:判断用户是否已经停止打字
我正在用 Java 创建一个简单的文本编辑器,并尝试添加撤消和重做功能。我希望程序能够确定用户是否已停止在文本区域中输入,而不仅仅是他们是否输入了字符。仅当他们只输入一个字符时,程序才应保存该字符。你会怎样做呢?
I'm creating a simple text editor in Java and I'm trying to add undo and redo functionality. I want the program to be able to determine if the user has stopped typing in the text area, not just whether they have entered a character. The program should save a single character only if it was the only thing they typed. How would you go about doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
定义“停止打字”。
基本上,我会考虑使用计时器。获取每个角色事件,添加一个计数器和一个计时器,每次出现“Key Up”事件时都会重新启动。将“停止打字”定义为已经过去了足够的时间。
然后想想你是否真的想这样做,因为这听起来会让我对开发人员的房子火把和干草叉发疯。
Define "stopped typing".
Bascially, I'd think about using a timer. Take each character event, add a counter and a timer that restarts every time there's a Key Up event. Define "stopped typing" as when enough time has passed.
Then think if you really want to do it that way, 'cause it sounds like something that would drive me absolutely torches-and-pitchforks-to-the-developer's-house mad.
主类中的某个地方;
在您的 KeyListener 接口中;
最后,在一个适当的、快速运行的线程中;
somewhere in a main class;
in your KeyListener interface;
and finally, in an appropriate, fast running thread;