Example 2 Drawing and Filling Oval

suggest change
import javax.swing.*;    
import java.awt.*;    

public class MyPanel extends JPanel {
    @Override
    public void paintComponent(Graphics g){    
        // clear the previous painting
        super.paintComponent(g);    
        Graphics2D g2 = (Graphics2D)g;    
        g2.setColor(Color.blue);    
        g2.drawOval(0, 0, 20,20);  
        g2.fillOval(50,50,20,20);    
    }
}

g2.drawOval(int x, int y, int width, int height);

This method draws an oval at the given x and y position with the given width and height.

g2.fillOval(int x, int y, int width, int height); This method fills an oval at the given x and y position with the given width and height.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents