强制侦听器执行



我有问题。

我有一个附加了侦听器的对象。

我希望能够手动执行它,以某种方式欺骗它触发它的事件发生。也许有一种方法可以访问特定的侦听器并告诉它执行?

对象是Box.Filler,侦听器是ComponentListener(适配器)。它在组件调整大小事件中激活。

好吧,

如果你使用ComponentListener我的猜测是你可以直接调用它:

listener.componentResized(new ComponentEvent (this,id))

如果您使用的是适配器

adapter.componentResized(new ComponentEvent (this,id))

如果您的类实现了组件侦听器

componentResized(new ComponentEvent (this,id))

您可以手动触发事件。如果您使用的是组件侦听器,则可以使用此接口中列出的方法之一,请参阅 http://docs.oracle.com/javase/1.4.2/docs/api/java/awt/event/ComponentListener.html。

最新更新