Design an Applet to Display Concentric Circle Using for Loop
Program to draw Concentric Circles on Applet
In this program, we have to draw four concentric circles as shown in output. ThesetFont( ) method is used to set the font in that you have to pass theFont 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.
This program demonstrates you the array of objects. Array of object is the collection of objects of the same class. The given syntax will define an array of reference therefore assign object to individual reference in the array to declare the array of object. The syntax to define array of object is: <class-name> <array-name> [size]; For example, the following statement will define an array of object having size 6 references to the class Box . Box b[6]; For creating an array of objects (allocating memory) you have to write down the following statements for (int i=0; i<6; i++) { b[i] = new Box(); // Assigning object to individual reference in the array. } PROGRAM import java.util.Scanner; public class Employee { int empid; String name; float salary; public void getInput() { Scanner in = new Scanner(System.in); System.out.print("Enter the empid :: "); empid = in.nextInt(); System.out.print("Enter the name :: ");
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.
In this program, first we first create a class Student which have data members name, roll_no, sub1, sub2 and one method to read data here getdata( ) method and show the result here show( ) method. We have used java.io.BufferedReader class to read data from keyboard at runtime. Then we have created an object of Student class in StudentDemo class and called the methods of Student class. When you compile the code using javac StudentDemo.java command two .class files will be created which are Student.class and StudentDemo.class , this has the advantage that you can reuse your .class file somewhere in other projects without compiling the code again. You can create as many classes as you want but writing many classes in a single file is not recommended as it makes code difficult to read rather you can create single file for every class. You can also group classes in packages for easily managing your code. PROGRAM import java.lang.*; import java.io.*; class Student
Program to create a simple Calculator using Java AWT components
This tutorial explains you how to create a simple Calculator using Java AWT components. The output of the program is given below.
Design an Applet to Display Concentric Circle Using for Loop
Source: https://www.javatutsweb.com/2016/11/program-to-draw-concentric-circles-on.html
0 Response to "Design an Applet to Display Concentric Circle Using for Loop"
Enregistrer un commentaire