Geertjan is a DZone Zone Leader and has posted 457 posts at DZone. You can read more from them at their website. View Full User Profile

5 Minutes: Putting a Memory Monitor in NetBeans IDE

02.01.2008
| 8089 views |
  • submit to reddit
Let's create a memory monitor for NetBeans IDE! "Geez. A memory monitor. That sounds hard. Where would one even begin?" Well, the answer to that question is the demo/management folder in the JDK. Handily, you'll find an application there called "MemoryMonitor". So I created a new module, used the Window Component wizard to create a TopComponent (specify that it should open in the "properties" position), copied the MemoryMonitor class from the demo into my source structure, and then added these lines to the TopComponent's constructor:
MemoryMonitor demo = new MemoryMonitor();
add(demo, java.awt.BorderLayout.CENTER);
demo.surf.start();
Thread thr = new Thread(new Memeater());
thr.start();

Plus, note that those lines actually come from the main method in the MemoryMonitor class. Since we don't need the main method anymore, we can plunder its content for whatever is relevant to us and then stick it in the TopComponent's constructor, as shown above. (You can then delete the main method, while leaving the rest of the MemoryMonitor class exactly as you found it.)

Then install the module! Before you do that, ponder this: "How much work have I actually done?" (Don't ponder too long, because the answer is that you've just done approximately 5 minutes of work and if you think about it too long you'll have spent more time thinking than working and, guess what, you could be porting another application instead.) Then... here's your new memory monitor in the IDE:

And you can detach it, of course, because of the undocking functionality of NetBeans IDE 6:

The monitor continually updates itself. How does it do that? No idea. I don't need to know that level of detail at all, unless I want to. That level of knowledge was completely irrelevant when porting the application to NetBeans IDE. I can be "clueless" about everything except for the tiny part of the module which concerns the integration with the NetBeans Platform. And all of that part was driven by a wizard. Now, let's see what other cool applications reside in the JDK's demo and sample folders...

 

Published at DZone with permission of its author, Geertjan Wielenga.

Comments

Rick Ross replied on Fri, 2008/02/01 - 6:42pm

5 minutes? Wow! This is awesome productivity! I think one of the biggest obstacles a lot of developers (myself included) have to overcome is the tendency to think we should build things from scratch. Learning to see what you can use or re-use in other people's code is a big step towards being more productive.

Nice piece, Geertjan, as usual. Well done!

Charles Ditzel replied on Fri, 2008/02/01 - 8:33pm

+1 ! This is useful. Thanks, Geertjan.

Matt Coleman replied on Wed, 2013/02/27 - 1:58am

wow..this is a great tip...so useful

buffalo ny SEO 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.