Geertjan's Blog

  • August 10, 2007

Anonymous Class to Inner Class

Geertjan Wielenga
Product Manager
One underhighlighted improvement in the upcoming NetBeans IDE 6.0 is that it will support keyboard users far more than before. When coding, I really hate having to break the flow of my activity by needing to call up dialog boxes and then having to click various things within them. Of course, there are ways of calling up those dialog boxes without using a mouse, but those keyboard combinations are a bit tricky and my life would be simpler if I could simply continue typing instead of needing to resort to dialog boxes. So, 6.0 comes to the rescue with its heavy focus on keyboard-based programming. Here's an example. You're adding an action listener to a JButton:

As one has been able to do in the past, one can let the IDE generate the required abstract methods, by simply clicking the hint that is shown above:

However, now I'm cleaning up my code and I don't want that class to be anonymous anymore. Instead, I want it to be an inner class. In the past, I'd have to call up a dialog box, click various things, and then the inner class would be created. In 6.0, I'll be able to simply select something in the anonymous class and then press Alt-Enter:

Then the small popup shown above appears. I simply press Enter again. And then... I have a new inner class:

And the anonymous class is transformed into a call to my inner class:

And if I don't like the name of my new inner class, I can simply click Ctrl-R over the name, and then I will be able to change the name, as well as references to it, in-line immediately, without any dialog boxes. Hurray!

Join the discussion

Comments ( 1 )
  • Philip Tuesday, August 21, 2007

    Features like those are nice, but almost unusable as they write the complete class path everywhere, e.g. "java.lang.String" instead of "String". And afterwards you can undo this crap. I hope it will have a smarter behaviour in the final release.

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha