1 // Fig. 6.16: DrawSmiley.java
2 // Demonstrates filled shapes.
3 import java.awt.Color;
4 import java.awt.Graphics;
5 import javax.swing.JPanel;
6
7 public class DrawSmiley extends JPanel
8 {
9 public void paintComponent( Graphics g )
10 {
11 super.paintComponent( g );
12
13 // draw the face
14 g.setColor( Color.YELLOW );
15 g.fillOval( 10, 10, 200, 200 );
16
17 // draw the eyes
18 g.setColor( Color.BLACK );
19 g.fillOval( 55, 65, 30, 30 );
20 g.fillOval( 135, 65, 30, 30 );
21
22 // draw the mouth
23 g.fillOval( 50, 110, 120, 60 );
24
25 // "touch up" the mouth into a smile
26 g.setColor( Color.YELLOW );
27 g.fillRect( 50, 110, 120, 30 );
28 g.fillOval( 50, 120, 120, 40 );
29 } // end method paintComponent
30 } // end class DrawSmiley
1 // Fig. 6.17: DrawSmileyTest.java
2 // Test application that displays a smiley face.
3 import javax.swing.JFrame;
4
5 public class DrawSmileyTest
6 {
7 public static void main( String args[] )
8 {
9 DrawSmiley panel = new DrawSmiley();
10 JFrame application = new JFrame();
11
12 application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
13 application.add( panel );
14 application.setSize( 230, 250 );
15 application.setVisible( true );
16 } // end main
17 } // end class DrawSmileyTest
Tidak ada komentar:
Posting Komentar