|
Draw arcs in java
In this example we are going to create an arc.
The Arcs can be drawn with draw Arc() and fill Arc(). We are using two type of package. One is java.awt.*
and second is java.applet.* .The java.awt.* is used for
GUI interface. AWT classes are contain in this package. The java.apple.*
package is used to create an applet.
In this we are using Graphics class and Applet
class. Here we are using three methods which are following:
void draw Arc ( int top, int width, int
height, int star tangle, int sweep Angle): This method is used to
draw the arc.
void fill Arc ( int top, int width, int
height, int star tangle, int sweep Angle): This method is used to
draw and fill the arc.
paint (Graphics g): This method is used to paint the
applet.
Here draw Arc and fill arc is use to
create arc. The arc is start from the start angle. if the sweep Angle is positive ("+ve") then the Arc is drawn
counterclockwise otherwise anticlockwise.
Here first we are importing two pacakages.Then after we
have write applet tag into comments. In this tag we have pass three arguments
code ,height and width. The code attribute is used to call the applet
class. And Height , width is used for Sizing the window.
Then we have create a class and extends this class with Applet Class to accurse the property of applet. We had override paint method of applet class.
//Draw Arcs
import java.awt.*;
import java.applet.*;
/*
<applet code="Arcs" width=300 height=200>
</applet>
*/
public class Arcs extends Applet
{
public void paint(Graphics g)
{
g.drawArc(10,20,50,50,0,130);
g.drawArc(40,50,70,60,0,65);
g.fillArc(70,90,100,90,0,230);}
}
|
Download source code
Output of Example

| | |