Search code examples
javaswingvariablesgraphicspaintcomponent

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


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.


Solution

  • Why not just do

    g.drawRect(myRectangleVariable.x, 
               myRectangleVariable.y, 
               myRectangleVariable.width, 
               myRectangleVariable.height);