public void paintComponent(final Graphics g) {
super.paintComponent(g);
g.setColor(Color.red);
g.drawOval(x,y,width,height);
g.fillOval(x,y,width,height);
}
This method draws the oval with x=2, y=2,width=10,height=10. How can i get the size of the drawing painted ?
Once it’s painted, that information becomes part of the component’s graphics context. There’s no easy way to retrieve it without examining the pixels. Instead, treat the oval’s size as constant, and use it in your calculation as shown here.