-2

我有个问题。

我有一个带有监听器的对象。

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

对象是 Box.Filler,侦听器是 ComponentListener(实际上是适配器)。它在 ComponentResized 事件上被激活。

4

2 回答 2

1

好吧,如果您使用ComponentListener我的猜测是您可以直接调用它:

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

如果您使用的是适配器

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

如果你的类实现了 ComponentListener

componentResized(new ComponentEvent (this,id))
于 2012-09-29T16:07:33.860 回答
0

您可以手动触发事件。如果您使用的是 ComponentListener,那么您可以使用此界面中列出的方法之一,请参阅http://docs.oracle.com/javase/1.4.2/docs/api/java/awt/event/ComponentListener.html

于 2012-09-29T16:02:58.507 回答