• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Draw rectangle by dragging mouse

 
Dheeraj Kasar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I want to draw a rectangle by dragging mouse using SWT. I am getting co-ordinates of starting point and endpoint but rectangle is not drawn.
Please help me about this.
Thanks in advance...
 
Campbell Ritchie
Sheriff
Pie
Posts: 50278
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Can you print out the coordinates? Presumably yes.
How are you doing the drawing? Which Graphics object are you using?
 
Dheeraj Kasar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here..I am posting my code...I have modified it. It is now displaying rectangle but during dragging mouse it is showing all mouse moves.

 
Campbell Ritchie
Sheriff
Pie
Posts: 50278
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you calling the makeRectangle method? Are you calling it from paintComponent? What's GC? Is it some sort of Graphics object? How did you write your PaintListener class?

Last time I had that exercise I created a Shape interfaceand a Rectangle class which implemented that interface and I put the object into a List and drew all the elements in that List in the paintComponent method. Of course, there is a Graphics object implicitly passed to the paintComponent method, ready for you to use. What about calling repaint() on the display from your mouse listener methods?

Please note the code button makes your posts look much better. I have edited your post, since you are new, to show it to full effect.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:How are you calling the makeRectangle method? Are you calling it from paintComponent? What's GC? Is it some sort of Graphics object? How did you write your PaintListener class?
...


I'm not sure if these concerns are relevant in GUI programs that use the SWT library, but I must plead ignorance since I don't use this library.

Pete
 
Campbell Ritchie
Sheriff
Pie
Posts: 50278
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. I hadn't noticed we were using SWT. Sorry.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic