Can someone please explain to me the difference or benefits rather to using the rectangle class
ex. Rectangle r1 = new Rectangle(x,y,w,h);
versus the graphics class drawRec method?
g.drawRec(x,y,w,h);
I'm thinking that you can create a new object outside of paint() or paintcomponent() which gives creating an object more options and maybe the associated methods is a bonus? I'm just speculating though because the tutorial I was going through switched from using one to the other without explaining why. I believe I understand how to use them just not when it's better to use which. Please try to keep your responses at the beginner level seeing as how I'm just starting out but of course any assistance is GREATLY appreciated. Thanks!!
Here is a code segment of what I'm working with:
public void paintComponent(Graphics g){
g.drawImage(yellowBall, xCoor, yCoor, this);
Rectangle r1 = new Rectangle((boardXSize/2), (boardYSize/2),50, 50);
g.setColor(Color.red);
g.fillRect(r1.x, r1.y,r1.width, r1.height);
repaint();
}