Example 2 Drawing and Filling Oval
suggest changeimport 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.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents