Home Java Example Java Awt Arcs Drawing In Java

Related Tutorials


 
 

Share on Google+Share on Google+

Arcs Drawing In Java

Advertisement
In this section, you will learn how to create arcs diagram in java awt package. The Java program uses Arcs2D class, arcs2D is the abstract superclass for all objects that store a 2D arc defined by a bounding rectangle, start angle, angular extent and a cl

Arcs Drawing In Java

     

Introduction:

In this section, you will learn how to create arcs diagram in java awt package. The Java program uses Arcs2D class, arcs2D is the abstract superclass for all objects that store a 2D arc defined by a bounding rectangle, start angle, angular extent and a closure type. Here, you wll see in the given following example that provides you the complete code of the program. 

Program Description:

The following program shows a frame title with "Arcs Draw". In this program you will also see how to show arcs diagram on the frame. There is two diagram you will see on frame, blank and color fill diagram. In this program we are using the BasicStroke() method. You can learn about this method in the previous program. Here, this program is using the "Arcs2D.Double" class. This class represent an arc defined by a bounding rectangle and closure type.

Here is the code of this program:

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

public class ArcsDraw extends Frame {
  Stroke drawingStroke = new BasicStroke(2);
  Arc2D arc=new Arc2D.Double(1409090145160180,  Arc2D.OPEN);
  Arc2D arc1=new Arc2D.Double(100509060140160,  Arc2D.OPEN);
 
  public void paint(Graphics g) {
  Graphics2D ga = (Graphics2D)g;
  ga.setStroke(drawingStroke);
  ga.setPaint(Color.yellow);
  ga.fill(arc);
  ga.draw(arc);
  ga.setPaint(Color.black);
  ga.draw(arc1);

  }

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

Output of this program:

 

Download this program.

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 13, 2008

Related Tutorials

Discuss: Arcs Drawing In Java  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com