1public void drawCenteredCircle(Graphics2D g, int x, int y, int r) {
2 x = x-(r/2);
3 y = y-(r/2);
4 g.fillOval(x,y,r,r);
5}
6
1public class scratch {
2 public static void main(String[] args) {
3 JFrame window = new JFrame();
4 window.setTitle("Christmas Tree");
5 window.setSize(700, 600);
6 window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
7 window.setVisible(true);
8 DrawingComponent DC = new DrawingComponent();
9 window.add(DC);
10 }
11}
12class DrawingComponent extends JComponent{
13 public void paint(Graphics graph0){
14 Graphics2D graph = (Graphics2D) graph0;
15 Ellipse2D.Double circle = new Ellipse.Double(5, 5, 25, 25);
16 graph.fill(circle);
17 }
18}
1import java.awt.*;
2import java.awt.event.*;
3import java.awt.geom.*;
4
5public class DrawCircle extends Frame
6{
7 // input the value for circle and square.
8 Shape circle=new Ellipse2D.Float(100.0f,100.0f,100.0f,100.0f);
9
10 // class paint to fill color in circle.
11 public void paint(Graphics g)
12 {
13 Graphics2D ga=(Graphics2D)g;
14 ga.draw(circle);
15 ga.setPaint(Color.blue);
16 ga.fill(circle);
17 }
18
19 public static void main(String args[])
20 {
21 // create a frame object for circle.
22 Frame frame=new DrawCircle();
23 frame.addWindowListener(new WindowAdapter()
24 {
25 public void windowClosing(WindowEvent we)
26 {
27 System.exit(0);
28 }
29 });
30 // circle coordinates.
31 frame.setSize(300, 250);
32 frame.setVisible(true);
33 }
34}
35