How to Draw Lines on the Screen (Part 2)

In part 1, I showed how you can click on the screen to create widgets and then connect those widgets together. But that's not really drawing, is it? (And I'm surprised nobody made that point in the comments to that blog entry.)

Drawing doesn't really revolve around connecting dots together. It's more about using a free-flow style and being able to randomly write stuff onto a screen, without constraints. Something like this:

I achieved the above by changing one line of code from the original referred to above. Instead of using a "mousePressed" event, I'm now using a "mouseDragged" event. That's all. And now the widgets are created when I drag my mouse on the scene. (I removed the rectangular select action, since that's also invoked during dragging and since that doesn't apply to the above scenario.)

Now, the next step is to rewrite the NetBeans Platform Paint Application Tutorial, so that the Visual Library is used. That would be pretty cool.


I don't think Visual Library would be a great choice for creating a paint application. You'll end up with a lot of Widgets, and Java2D is much better for creating bitmaps. Maybe Vislib could be used in combination with it for providing tools though. E.g. you could easily create a selection rectangle, or an eraser you can move to manipulate the background.

Thanks for your recent blog posts about vislib. Lot's of useful code snippets :-)!

Posted by Toni Epple on September 13, 2012 at 03:57 AM PDT #

That would be great! I should provide the examples I need!

Posted by Javier Ortiz on September 13, 2012 at 07:17 AM PDT #

I am fascinated by your "mouse dragging" technique to create more realistic screen writing. I thought that 'net' and 'beans' were both created in widget format; obviously, my untrained eye! Which one is done by dragging? Or am I being naive enough to not even know how to ask the question? LOL or not! :)K

Posted by guest on September 16, 2012 at 03:16 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« July 2016