Home Java Example Java Swing Graphics2D Draw An Arc in Graphics



Draw An Arc in Graphics
Posted on: October 16, 2008 at 12:00 AM
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

Related Tags for Draw An Arc in Graphics:
cclasslistconstructorstructfloatsed2dconstvalueintlinebasicshowirctodrawbasicsrawssecissiwsshecircleliicsuseimceinpasscsasmntoutoutlinetrstiarcclesrcmehowintotorsthicknessctoressatkisirhaimpressivpressprerc2andarconsstrsegmentvassrenthshociravstaluctofeprndono


More Tutorials from this section

Ask Questions?    Discuss: Draw An Arc in Graphics   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.