Tuesday, 29 November 2016

Program to design an applet which displays three circles one below the other and fill them red, green and yellow color respectively

Given program will draw three circle one below other with colours red, green and blue respectively. To fill circle with respective colours first we have to set the colour using setColor(Color c) method of Graphics class and then use the fillOval( ) method.


PROGRAM
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;

public class ThreeCircleApplet extends Applet {

 public void paint(Graphics g) {
  
  // First circle filled with RED color
  g.setColor(Color.RED);
  g.fillOval(50, 50, 50, 50);
  
  // Second circle filled with GREEN color
  g.setColor(Color.GREEN);
  g.fillOval(50, 100, 50, 50);
  
  // Third circle filled with YELLOW color
  g.setColor(Color.YELLOW);
  g.fillOval(50, 150, 50, 50);
 }
}

/* <applet code="ThreeCircleApplet" width=200 height=250>
   </applet>
*/

OUTPUT

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



No comments:

Post a Comment