• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Draw rectangle by dragging mouse

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Marshal
Posts: 79412
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79412
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79412
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you. I hadn't noticed we were using SWT. Sorry.
reply
    Bookmark Topic Watch Topic
  • New Topic