Home Java Example Java Awt How to Create Circle In Java



How to Create Circle In Java
Posted on: March 13, 2008 at 12:00 AM
This is a simple program of java awt. In this section, you will learn how to create Circle Diagram. The java circle is the most fundamental abstractions in a Java 2D in the supported java.awt.shape package. It describes a shape. But the Java 2D definitio

How to Create Circle In Java

     

Introduction:

This is a simple program of java awt. In this section, you will learn how to create Circle Diagram. The java circle is the most fundamental abstractions in a Java 2D in the supported  java.awt.shape package. It describes a shape. But the Java 2D definition of a shape does not require the shape to enclose an area. The Java2D API  also provides several classes that defines common Geometric Objects. 

Program Description:

In this program, you will also show that how to create square drawing. Inside the program define a class name CircleDraw for the circle component.  There is created two types of diagrams "Circle" and "square" for this program. Here, this program uses Ecllpise2D that is implemented to specify eclipse float and double. double and float components are represented for creating the square and circle in this program. 

setPaint(): This class is used for filling the color.

Here is the code of this program:

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;

public class CircleDraw extends Frame {
  Shape circle = new Ellipse2D.Float(100.0f100.0f100.0f100.0f);
  Shape square = new Rectangle2D.Double(100100,100100);
  public void paint(Graphics g) {
  Graphics2D ga = (Graphics2D)g;
  ga.draw(circle);
  ga.setPaint(Color.green);
  ga.fill(circle);
  ga.setPaint(Color.red);
  ga.draw(square);
  }

  public static void main(String args[]) {
  Frame frame = new CircleDraw();
  frame.addWindowListener(new WindowAdapter(){
  public void windowClosing(WindowEvent we){
  System.exit(0);
  }
  });
  frame.setSize(300250);
  frame.setVisible(true);
  }
}

Output this program:

Download this program.

Related Tags for How to Create Circle In Java:
javacapicomideclassuiobjectfunioobjectsclasses2ddiagramviporttracdefinitionawtabstractionthisidactionpackagesupportsimplecreateabstractclosedefineircprogramtoinilearnramrequiressecisheareilshapeitareacircledesrtesectionnotlsbstractionsinitpeiminnoshaasmnttrososjndapackclescommonagepircmehowobjproppackgeododescribessusodefinesbstatpacrackmetricisirhallmpldiaeaaractclosstrrtsimwtvascrssrithciravbesstabaphatctsdamfinlsojepleplprmostndonomogro


More Tutorials from this section

Ask Questions?    Discuss: How to Create Circle In Java   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.