Home Java Example Java Swing Graphics2D Draw An Arc in Graphics
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Draw An Arc in Graphics

Advertisement
An arc of a circle is a segment of the circumference of the circle. To draw an arc, class Arc2D is used.

Draw An Arc in Graphics

     

In this section, you will learn how to draw an arc in Graphics.

An arc of a circle is a segment of the circumference of the circle. To draw an arc, class Arc2D is used. To give the stylistic and impressive way to the outline of arc, we have used BasicStroke class. The float value passed into the constructor of Class BasicStroke shows the thickness of the outline.

The method setPaint() paints the shape with specified color. The method setStroke() sets the stroke settings. The method frame.setSize() sets the size of frame and frame.show() shows the frame.

 

 

Here is the code of DrawAnArc.java

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

public class DrawAnArc extends JApplet {
  BasicStroke basicStroke = new BasicStroke(5.0f);  
  public void paint(Graphics g) {
  Graphics2D g2d = (Graphics2D) g;
  g2d.setPaint(Color.red);
  g2d.setStroke(basicStroke);
  g2d.draw(new Arc2D.Double(51015015060150,
  Arc2D.OPEN));
  }
  public static void main(String s[]) {
  JFrame frame = new JFrame("Draw Arc");
  JApplet applet = new DrawAnArc();
  frame.getContentPane().add("Center", applet);
  frame.setSize(300250);
  frame.show();
  }
}

Download Source Code

Download Source code

Advertisements

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: October 16, 2008

Related Tutorials

Ask Questions?    Discuss: Draw An Arc in Graphics   View All Comments

Post your Comment


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