How to initialize and draw a Rectangle variable in a paintComponent method? [closed]

Tags: , , , ,

I’ve been trying to add collision to my game, it seemed like a piece of cake, I already know how to draw a rectangle. But I need that rectangle to be represented by something, a variable. But it seems like there’s no method like g.drawRect(myRectangleVariable). I need to do some if statements checking for intersection but if I don’t have a rectangle variable then what do I compare? If you guys need any of my code just tell me.


Why not just do


Source: stackoverflow