• Post Reply Bookmark Topic Watch Topic
  • New Topic

draw rectangle in JPanel using mouse  RSS feed

 
Subitha Sangar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any one could please help me to give idea "how to draw a rectangle using mouse in Jpanel" and it should allow to draw more than one rectangle or other shapes.. if anyone have sample code please give it and help me... thanks in advance.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
add a mouseListener to the panel
mousePressed get the x/y coords
mouseReleased get the x/y coords and repaint()
paintComponent() has graphics.drawRect(coords)
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please do not post the same message in multiple forums.

Thank you,

Layne
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please CarefullyChooseOneForum when posting at the Ranch. This question ought to have gone to the Swing Forum, where I'm moving it now.
[ January 10, 2006: Message edited by: Ernest Friedman-Hill ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!