开发者

how generate automatic addWindowListener(new ExitListener()); in intellij 10.0.3

Is it possible? I am using free version - community. My friend was helping me with one project and when he wrote addWindwListener, intelliJ generated him new separete file class with 开发者_StackOverflowfull implementation inside:

public class ExitListener extends WindowAdapter {
  public void windowClosing(WindowEvent event) {
    System.exit(0);
  }
}

How to make my intellij to write as above? Is it any shortcuts or anything which will tell me what can i write? I tried ALT+Insert but i am not sure it is good way..


This is called "Intention Actions" in the help documentation. It works as follows - If you type

addWindowListener(new ExitListener());

and the class ExitListener isnt created yet, you can have Idea generate it for you. Just move cursor over the red colored class name and hit ALT + ENTER, Idea will pop up alist of available intentation actions, suggesting to create class ExitListener, just press ENTER again and the class will be created with proper inheritence, without implementation however. To generate default implementation you must hit ALT + INSERT and choose implement methods.

Your friend probably did it very fast for you to notice manual implementation generation.

You can also do it very fast using following procedure -

1. ALT + ENTER and select create class
2. ALT + INSERT, select implement methods

and you're done.


There is no need to use a WindowListener. Just use:

frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

It's better to learn Swing then to learn how to use an IDE.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜