Program to use control loops in Applets

Here, we have shown four circle one below other using "for" loop with two different colors. The methods used are drawOval( )fillOval( ) and setColor( ). Details of these methods are given in previous programs.


PROGRAM
import java.awt.*;
import java.applet.*;

public class ControlLoopApplet extends Applet
{
 public void paint(Graphics g)
 {
  
  
  
  for(int i=1;i<=4;i++)
  {
   if(i%2==0)
   {
    g.fillOval(90,i*50+10,50,50);
    g.setColor(Color.black);
   }
   else
   {
    g.drawOval(90,i*50+10,50,50);
    g.setColor(Color.red);
   }
  }
 }
}
/* <applet code=ControlLoopApplet width=300 height=300>
  </applet> */

OUTPUT

C:\>javac ControlLoopApplet.java
C:\>appletviewer ControlLoopApplet.java



Popular posts from this blog

Program to define a class 'employee' with data members as empid, name and salary. Accept data for 5 objects using Array of objects and print it.

Define a class Student with four data members such as name, roll no.,sub1, and sub2. Define appropriate methods to initialize and display the values of data members. Also calculate total marks and percentage scored by student.