This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
An off-topic question regarding basic Java Programming
#6
It works ^^ Thanks Itaru Smile

It seems that all kinds of drawing activities must be done inside paintComponent, and the listeners are meant to provide data necessary for drawing... Am I right ?

Would you please explain what this piece of code do ? (I know that it is another way to write "if" statement, but what is the logic behind this ?)
Code:
int x = (start.x < end.x) ? start.x : end.x;
int y = (start.y < end.y) ? start.y : end.y;
panel.repaint(x, y, Math.abs(start.x - end.x) + 1, Math.abs(start.y - end.y) + 1);

*Edit : I've managed to find my mistake... Before, I only call repaint(). It should be panel.repaint().... And then we must set a flag so that the paintComponent will fill the rectangle just once. This way, when mouseMoved() calls panel.repaint() , only the line is drawn. The rectangle is not refilled again.

Reply


Messages In This Thread
RE: An off-topic question regarding basic Java Programming - by tr4nquility - 11-25-2011, 04:43 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)