Results 1 to 1 of 1
  1. #1
    Java Example is offline Moderator
    Join Date
    Sep 2014
    Posts
    27
    Rep Power
    0

    Default How to create Circle Diagram in java AWT?

    In this tutorial ,we will illustrate how to create Circle Diagram. The java circle is the most fundamental abstractions in a Java 2D in the supported java.awt.shape package. Java2D API provides several classes that defines common Geometric Objects. In the example below, we show 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.

    Java Code: Program to create a circle in java AWT
     
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    
    public class CircleDraw extends Frame {
    
        Shape circle = new Ellipse2D.Float(100.0f, 100.0f, 100.0f, 100.0f);
        Shape square = new Rectangle2D.Double(100, 100, 100, 100);
    
        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(300, 250);
            frame.setVisible(true);
        }
    }
    Output of this program:

    How to create Circle Diagram in java AWT?-circle.jpg
    Figure: Program output with circle and square
    Last edited by Java Example; 09-11-2014 at 04:54 PM.

Similar Threads

  1. Circle within Circle in Android
    By raihan26 in forum Android
    Replies: 0
    Last Post: 08-12-2012, 08:41 PM
  2. How to create a JFrame window and create a circle.
    By tehsumo in forum AWT / Swing
    Replies: 3
    Last Post: 02-27-2012, 04:06 PM
  3. Alternative way to create a circle propagation?
    By Kratos321 in forum New To Java
    Replies: 8
    Last Post: 05-26-2011, 04:23 AM
  4. How to generate Data Flow Diagram(Work Flow Diagram)
    By stsivaraj in forum AWT / Swing
    Replies: 1
    Last Post: 12-22-2010, 11:21 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •