Reputation: 1365
I want to draw an oval exactly within the panel, similar to
@Override
public void paint(Graphics g) {
super.paint(g);
g.drawOval(x,y,this.getHeight(), this.getHeight() );
}
}
where x
and y
according to java.awt.Graphics
documentation:
x: the x coordinate of the upper left corner of the oval to be drawn.
y: the y coordinate of the upper left corner of the oval to be drawn.
So what should x
and y
be?
Upvotes: 1
Views: 124
Reputation: 91
Both x
and y
should be 0, as this sets the upper left corner of the oval to be at the upper left corner of the JPanel
. Also, the line:
g.drawOval(x,y,this.getHeight(), this.getHeight() );
should actually be
g.drawOval(x, y, this.getWidth(), this.getHeight());
to ensure that the oval is drawn properly; else, it will simply be circular no matter the size of the JPanel
.
Upvotes: 2