Program to draw Concentric Circles on Applet

In this program, we have to draw four concentric circles as shown in output. The setFont( ) method is used to set the font in that you have to pass the Font class's object. You have to pass font name, font style and font size in Font's constructor like:
g.setFont(new Font("Times New Roman", Font.BOLD|Font.ITALIC, 14));

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

public class ConcentricCircles extends Applet
{
 public void paint(Graphics g)
 {
  g.setFont(new Font("Times New Roman",Font.BOLD|Font.ITALIC,14));
  g.drawString("Concentric Circles",30,30);
  int i=65,j=65;
  while(i>=30)
  {
   g.drawOval(i,i,j,j);   
   i = i - 10;
   j = j + 20;
  }
 }
}

/* <applet code=ConcentricCircles width=200 height=200>
  </applet> */

OUTPUT

C:\>javac ConcentricCircles.java
C:\>appletviewer ConcentricCircles.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.

Program to input age from user and throw user-defined exception if entered age is negative