Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Rectangle Not coming+swing

 
Vas Miriyala
Ranch Hand
Posts: 114
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got this program from herewebpage ,Window is coming but Rectangle is not showing in a winodow
here is the code

 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works fine for me, but I would suggest that when drawing on JComponents and anything that is derived from this, you override paintComponent, not paint. For example:
 
Vas Miriyala
Ranch Hand
Posts: 114
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot ,now its working fine
 
Vas Miriyala
Ranch Hand
Posts: 114
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have one doubt? that is if i want to move a small rectangle along with x-axis,what am i suppose to do? any idea?
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
srinivas miriyala wrote:I have one doubt? that is if i want to move a small rectangle along with x-axis,what am i suppose to do? any idea?


Right now, because you draw the rectangle using int literals (10, 10, 200, 200), it is hard-coded to have its left upper corner located at [10, 10], relative to the JComponent it sits in. If you want to move the rectangle, you're along the x axis, you're going to have to use a variable for the first parameter of drawRect, change that variable in a Swing Timer, and call repaint on the MyCanvas object after changing the variable.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic