Draw Oval and Circle in Applet Window - Java Applet

Java examples for Applet:Applet Creation

Description

Draw Oval and Circle in Applet Window

Demo Code



import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JComponent;

public class Main extends JComponent {

  public void paint(Graphics g) {

    setForeground(Color.red);//ww  w.  j  a v  a 2  s. co m

    // draw a oval of width 50 & height 100 at (10,10)
    g.drawOval(10, 10, 50, 100);

    /*
     * To draw a filled oval use fillOval(int x1,int y1, int width, int height)
     */

    // draw filled oval
    g.fillOval(100, 20, 50, 100);

  }
}

Related Tutorials