-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDonutBoard.java
More file actions
35 lines (30 loc) · 925 Bytes
/
DonutBoard.java
File metadata and controls
35 lines (30 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.awt.*;
import java.awt.geom.*;
import javax.swing.JPanel;
public class DonutBoard extends JPanel
{
public DonutBoard()
{
}
// all the drawing is done in this method
public void paint( Graphics g )
{
super.paint( g );
Graphics2D g2d = ( Graphics2D )g;
// do drawings
Ellipse2D e = new Ellipse2D.Double( 0, 0, 80, 130 );
g2d.setStroke( new BasicStroke( 1 ) );
g2d.setColor( Color.GREEN );
// get the height and weight of this object (panel)
Dimension size = getSize();
double w = size.getWidth();
double h = size.getHeight();
// repeatedly draw a transformed ellipse "e" at every 5 degree increment
for( double deg = 0; deg < 360; deg += 5 )
{
AffineTransform at = AffineTransform.getTranslateInstance( w/2, h/2 );
at.rotate( Math.toRadians( deg ) );
g2d.draw( at.createTransformedShape( e ) );
}
}
}