Java Reference
In-Depth Information
50
gg.fillRect( 4 , 4 , 3 , 3 ); // draw a filled rectangle
51
52
// paint buffImage onto the JFrame
g2d.setPaint( new TexturePaint(buffImage,
new Rectangle( 10 , 10 )));
g2d.fill(
new RoundRectangle2D.Double( 155 , 30 , 75 , 100 , 50 , 50 ));
53
54
55
56
57
58
// draw 2D pie-shaped arc in white
g2d.setPaint( Color.WHITE );
g2d.setStroke( new BasicStroke( 6.0f ));
g2d.draw(
new Arc2D.Double( 240 , 30 , 75 , 100 , 0 , 270 , Arc2D.PIE) );
59
60
61
62
63
64
// draw 2D lines in green and yellow
g2d.setPaint( Color.GREEN );
g2d.draw( new Line2D.Double( 395 , 30 , 320 , 150 ));
65
66
67
68
// draw 2D line using stroke
69
float [] dashes = { 10 }; // specify dash pattern
70
g2d.setPaint( Color.YELLOW) ;
71
g2d.setStroke( new BasicStroke( 4 , BasicStroke.CAP_ROUND ,
72
BasicStroke.JOIN_ROUND , 10 , dashes, 0 ));
73
g2d.draw( new Line2D.Double( 320 , 30 , 395 , 150 ));
74
}
75
} // end class ShapesJPanel
Fig. 13.29 | Demonstrating some Java 2D shapes. (Part 2 of 2.)
1
// Fig. 13.30: Shapes.java
2
// Testing ShapesJPanel.
3
import javax.swing.JFrame;
4
5
public class Shapes
6
{
7
// execute application
8
public static void main(String[] args)
9
{
10
// create frame for ShapesJPanel
11
JFrame frame = new JFrame( "Drawing 2D shapes") ;
12
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
13
14
// create ShapesJPanel
15
ShapesJPanel shapesJPanel = new ShapesJPanel();
16
17
frame.add(shapesJPanel);
18
frame.setSize( 425 , 200 );
19
frame.setVisible( true );
20
}
21
} // end class Shapes
Fig. 13.30 | Testing ShapesJPanel . (Part 1 of 2.)
Search WWH ::




Custom Search