开发者

In WindowListener,how to avoid all methods declaration while using a single eventof WindowClosing()?

(WindowClosing) when i am using window event for closing c开发者_运维知识库urrent frame, in that it asked import all abstract methods.. How to import windowClosing event without import all sbstract methods?


You want to use a WindowAdapter instead of a WindowListener. WindowAdapter is abstract but has no abstract methods (it implements them with empty methods) so that you only override the methods you actually want to work with.


Use a WindowAdapter - all the Swing listeners have a "stub" implementation that implements the methods of the listener interface with empty methods. This way you only have to override the methods you need. Be sure to use the @Override annotation to detect any problems such as method name misspellings / leaving out parameters / etc.


A Frame has different closing possibilities by itself. I assume you found that out, and want to make a WindowListener without writing all of the methods which you don't need. In that case, use a WindowAdapter which happens to be a WindowListener with all methods implemented. You can override the ones you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜