by Dinesh Thakur Category: AWT and Applets

An arc can be drawn using the drawArc () method. This method takes six arguments in which the first four are same as the arguments of the drawoval () method and the next two represents the starting angle of the arc and the sweep angle around the arc, respectively.

The general form of the drawArc () method is:

void drawArc (int a1, int b1, int w, int h, int strt_angle, int sweep_angle)

where,

a1, b1 is the coordinate of the top left comer of the bounding rectangle

w is the width of the bounding rectangle

h is the height of the bounding rectangle

strt _angle is the starting angle of the arc (in degrees)

sweep_angle is the number of degrees (angular distance) around the arc (in degrees)

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class DrawArc extends Applet {
public static void main(String[] args) {
Frame DrawArcApplet = new Frame("Draw Arc in Applet Window Example");
DrawArcApplet.setSize(350, 250);
Applet DrawArc = new DrawArc();
DrawArcApplet.add(DrawArc);
DrawArcApplet.setVisible(true);
DrawArcApplet.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
      }
    });
  }
  public void paint(Graphics g) {
    // draws String
    g.drawString("This is Arc Shapes Example", 100, 70);
    // Draws an Arc Shape
    g.drawArc(30,5, 200, 200, 0, -90); //Syntax For:- drawArc(int xTopLeft, int yTopLeft, int width, int height, int startAngle, int arcAngle);
   
    // Fill an Arc Shape
    g.fillArc(30, 5, 200, 200, 0, -90);  //Syntax For:- fillArc(int xTopLeft, int yTopLeft, int width, int height, int startAngle, int arcAngle);
  }
}

 

Draw Arc in Applet Window Example



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles