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
#7
Yes, all drawings should be done in the paint...() methods since they will not be drawn immediately anywhere else. The listeners just update the state of the objects to be drawn and call the proper repaint() method to tell the system to draw them.

That piece of code is to determine the position and size of the rectangle that contains the line to be drawn. That panel.repaint() method will only repaint the area bounded by that rectangle (which contains the line) to avoid repainting the whole panel. The logic for x and y determines the top-left most position of the rectangle, and the calculations inside Math.abs determine its width and height. I added 1 to the size calculations since the line to be drawn is 1 pixel wide.

BTW, which flag are you talking about? To optimize the panel drawing, it's probably a good idea to set the doublebuffering flag to true and the opaque flag to false.
Reply


Messages In This Thread
RE: An off-topic question regarding basic Java Programming - by Itaru - 11-25-2011, 05:37 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)