This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
I'm making a simple game where a ball moves around the screen according to key movements. I've used basic physics equations to calculate the position according to the summed forces of the Environment (my object to extend JPanel). The paint() is called on a timer which repaints every 10 milliseconds. That's all in working order. At the moment, I've added a laser to the ball which rotates in accordance to the MouseMotionListener, which utilizes the same painting technique in my paint method (AffineTransform rotate method is set to zero typically and then changed when mouse is moved). That is also in working order. My problem is with the actual laser shot. I've added a MouseListener to initiate the drawing of the shot from the barrel (a simple line2D object). Unfortunately, calling repaint() here doesn't always beat the repaint() being called in the Timer. It's about a 50% chance that the laser actually paints when clicked. So what I need to know is what exactly this Graphics object is? I understand that Java calls it whenever the component is updated or repaint() is called, but what is it associated with? I would like to be able to create a second paint method (without creating another panel) that I can call manually. Can I do this with getGraphics()? What would I call getGraphics() on?
TOO LONG DIDN"T READ: What is a Graphics object exactly? How can I create my own so I can feed it into a second paint() method? I'm looking to make a second method so different calls to repaint() don't interrupt each other, as they are being called from different contexts. (Would I call getGraphics() on my JPanel and simply feed it into a second method "paint2" or something?)
Sorry, if it's kind of long, let me know if I need to clarify.
EDIT: Semi-resolved issue. Posting shorter, more focused question.