Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Looking for simple rectangle drawing source code

Reply
Thread Tools

Looking for simple rectangle drawing source code

 
 
Ramon
Guest
Posts: n/a
 
      12-18-2004
I need to write a very simple "visual" widget drawing application.

The app user will select an item from a palette and then
by click and drag, create a rectangle.

This must be the most common (after a simple click) operation
in all the GUI environments.

Anyway, I am looking for the code that implements the
reactangle drawing/erasing as the mouse is dragged around.
Any pointers??

TIA,

-Ramon

 
Reply With Quote
 
 
 
 
klynn47@comcast.net
Guest
Posts: n/a
 
      12-18-2004
You might look at MouseMotionListener and MouseListener. The method for
drawing a rectangle is simple. The method is drawRect and accepts 4
parameters. The first two are the x and y coordinates of the upper left
corner of the rectangle. The third is the width, and the fourth is the
height.

 
Reply With Quote
 
 
 
 
Andrei Kouznetsov
Guest
Posts: n/a
 
      12-18-2004
>I need to write a very simple "visual" widget drawing application.
>
> The app user will select an item from a palette and then
> by click and drag, create a rectangle.
>
> This must be the most common (after a simple click) operation
> in all the GUI environments.
>
> Anyway, I am looking for the code that implements the
> reactangle drawing/erasing as the mouse is dragged around.
> Any pointers??


it is very easy...

while mouse dragging you make following:

first getGraphics from your Component or Canvas or whatever.
then you set XOR painting mode on that Graphics
then if there exist saved(!) rectangle you draw it.
then you draw current rectangle.
then you save your current rectangle.
and dispose Graphics

thats it!

--
Andrei Kouznetsov
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Guide to the standard library? Library for drawing in GUIs?drawing inbrowsers? defn noob Java 1 06-28-2008 02:50 AM
Drawing a rectangle around an image Elliot Java 1 11-14-2007 08:46 PM
funny drawing software:ScreenPen,drawing directly on screen! yyzzbb@sina.com Digital Photography 0 02-04-2006 12:31 AM
System.Drawing For Drawing Text Images jjbutera@hotmail.com ASP .Net 1 01-09-2006 09:55 PM
Rectangle object in asp.net? Kenneth ASP .Net 1 01-15-2004 08:53 AM



Advertisments