> drawing arcs in java ~ Online tutorial

drawing arcs in java

Drawing Arcs

  • An arc is a portion of a oval. Arc angles are measured in degrees. Arcs sweep from a starting angle the number of degrees specified by their arc angle.
  • The starting angle indicates in degrees where the arc begins.
  • The arc angle specifies the total number of degrees through which the arc sweeps.
  • The left set of axes shows an arc sweeping from zero degrees to approximately 110 degrees.
  • Arcs that sweep in a counterclockwise direction are measured in positive degrees.
  • The right set of axes shows an arc sweeping from zero degrees to approximately –110 degrees.
  • Arcs that sweep in a clockwise
    direction are measured in negative degrees.
public void drawArc( int x, int y, int width, int height,
int startAngle, int arcAngle )
Draws an arc relative to the bounding rectangle’s top-left coordinates (x, y)
with the specified width and height. The arc segment is drawn starting at
startAngle and sweeps arcAngle degrees.

public void fillArc( int x, int y, int width, int height,
int startAngle, int arcAngle )
Draws a solid arc (i.e., a sector) relative to the bounding rectangle’s top-left
coordinates (x, y) with the specified width and height. The arc segment
is drawn starting at startAngle and sweeps arcAngle degrees.

Program

2 // Drawing arcs
3 import java.awt.*;
4 import javax.swing.*;
5 import java.awt.event.*;
67
public class DrawArcs extends JFrame {
8 public DrawArcs()
9 {
10 super( "Drawing Arcs" );
11
12 setSize( 300, 170 );
13 show();
14 }
15
16 public void paint( Graphics g )
17 {
18 // start at 0 and sweep 360 degrees
19 g.setColor( Color.yellow );
20 g.drawRect( 15, 35, 80, 80 );
21 g.setColor( Color.black );
22 g.drawArc( 15, 35, 80, 80, 0, 360 );
23
24 // start at 0 and sweep 110 degrees
25 g.setColor( Color.yellow );
26 g.drawRect( 100, 35, 80, 80 );
27 g.setColor( Color.black );
28 g.drawArc( 100, 35, 80, 80, 0, 110 );
29
30 // start at 0 and sweep -270 degrees
31 g.setColor( Color.yellow );
32 g.drawRect( 185, 35, 80, 80 );
33 g.setColor( Color.black );
34 g.drawArc( 185, 35, 80, 80, 0, -270 );
35
36 // start at 0 and sweep 360 degrees
37 g.fillArc( 15, 120, 80, 40, 0, 360 );
38
39 // start at 270 and sweep -90 degrees
40 g.fillArc( 100, 120, 80, 40, 270, -90 );
41
42 // start at 0 and sweep -270 degrees
43 g.fillArc( 185, 120, 80, 40, 0, -270 );
44 }
45
46 public static void main( String args[] )
47 {
48 DrawArcs app = new DrawArcs();
49
50 app.addWindowListener(
51 new WindowAdapter() {
52 public void windowClosing( WindowEvent e )

53System.exit( 0 );
55 }
56 }
57 );
58 }
59 }


Buy It Now




Please Give Us Your 1 Minute In Sharing This Post!
Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Powered By: BloggerYard.Com

0 comments: