Draw Oval in Applet

drawOval() is the method of a Graphics class.To draw a oval we use drawOval(int xaxis,int yaxis,int widthh, int heightt) method.

 

/* <applet code="LApplet" height=400 width=400> </applet> */

import javax.swing.*;                              

import java.awt.*;

import java.applet.*;

public class LApplet extends Applet

{

     public LApplet()

      {

         setForeground(Color.red);

         setBackground(Color.blue);

      }

     public void init()

     {

         Label l1= new Label("XCnotes.com");

         add(l1);

         Button b1= new Button("Good Program");

        add(b1);

     }

    public void paint( Graphics g)

     {

         int countr=1;

        do

          {

               g.drawOval(110-countr*10,110-countr*10,countr*20,countr*20);

                 ++countr;

           }

          while(countr<=10);

     }

}

Explanation…

The life cycle of an applet begins when it is first loaded and the init() method is invoked. This method is invoked only once during the entire lifetime of an applet. The body of the method includes statements related to variable initialization, object creation, adding components like buttons, textboxes etc. setting colors of the applet, loading of images or fonts etc.

Paint() is invoked to display the output on the screen in the form of text, graphics etc.

Draw Oval in Applet

About Us

Rekha SetiaRekha Setia is a passionate blogger of Extra Computer Notes. if you have any ideas or any request me @