Tuesday, 29 November 2016

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



No comments:

Post a Comment