I'm trying to develop a Java brick breaker (like DxBall) game and I want to make the Ball
object with its own draw method.
What I'm trying to do:
public class Ball {
private int x, y, diameter;
public void Ball(){
x = 0;
y = 0;
diameter = 20;
}
public void draw(Graphics g){
g.setPaint(Color.red);
g.fillOval(x, y, diameter, diameter);
}
}
Therefore, my game engine extends JFrame
and its paintComponent
method will call game objects draw method. To sum, is it proper way to do object oriented game in Java? What should my Ball
class extend?