在这KeyListeners将被称为​​保证的顺序? [英] Is the order in which KeyListeners will be called guaranteed?

查看:135
本文介绍了在这KeyListeners将被称为​​保证的顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可能会丢失的<一个文档中的这个东西很明显href=\"http://download.oracle.com/javase/6/docs/api/java/awt/Component.html#addKeyListener%28java.awt.event.KeyListener%29\"相对=nofollow> addKeyListener ,<一个href=\"http://download.oracle.com/javase/6/docs/api/java/awt/Component.html#removeKeyListener%28java.awt.event.KeyListener%29\"相对=nofollow> removeKeyListener ,的 getKeyListeners 或相关的教程,但是否有关于它增加了按键侦听器的运行顺序任何保证?我的希望是,他们在其所加入的顺序运行,但我不明白,这是在任何地方指定。

I may be missing something obvious about this in the documentation for addKeyListener, removeKeyListener, getKeyListeners or associated tutorials, but are there any guarantees about the order in which added key listeners are run? My hope is that they are run in the order in which they are added, but I don't see that this is specified anywhere.

我的情况是,我需要一个按键侦听器添加到现有的组件并覆盖现有的按键侦听特定的键。看来,一个人应该能够通过做到这一点:

The situation I have is that I need to add a key listener to an existing Component and override the existing key listeners for particular keys. It seems that one should be able to do this by:


  • 使用 getKeyListeners 来找到所有现有的keylisteners。

  • removeKeyListener 删除现有的每个按键侦听器

  • 使用 addKeyListener 来增加我的钥匙侦听器。 (这仅涉及选择的关键presses,并且消耗的时候情况确实如此。)

  • 最后加回所有在第一步中被发现 addKeyListener ,关键听众。

  • Using getKeyListeners to find all the existing keylisteners.
  • Remove each existing key listener with removeKeyListener
  • Use addKeyListener to add my key listener. (This only deals with selected keypresses, and consumes the event when it does.)
  • Finally add back all the key listeners that were found in the first step with addKeyListener.

不过,我不想这样做,如果事实证明,它不会在特定的JVM工作,等等。

However I don't want to do this if it turns out that it won't work on particular JVMs, etc.

推荐答案

我不太了解你的情况。依托在听众被称为顺序似乎有点冒险。

I don't quite understand your situation. Relying on the order in which listeners are called seems a little bit dodgy to me.

难道你们就不能只是创建当你的事件发生,其检测的关键监听器包装类,比代表适当如果该事件对包装监听器类(ES)?

Can you not just create a key listener wrapper class which detects when your event happens, and if appropriate than delegates the event to the wrapped listener class(es)?

我觉得有你想达到不依赖于监听器排序,除非我误解了什么东西实现更好的方法!

I think there are better ways of achieving what you want to achieve without relying on listener ordering, unless I have misunderstood something!

这篇关于在这KeyListeners将被称为​​保证的顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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