Tampilan Program
Dan berikut ini contoh program lengkapnya:
01import java.awt.*;
02
03import javax.swing.*;
04
05public class DrawPolygons extends JFrame {
06
07 public DrawPolygons() {
08 super ("Menggambar Polygon");
09 setSize (400,300);
10 show();
11 }
12
13 public void paint(Graphics g) {
14 super.paint (g);
15
16 int xValues[] = {20,40,50,30,20,15};
17 int yValues[] = {50,50,60,80,80,60};
18 Polygon poly1 = new Polygon (xValues, yValues, 6); //(arrX, arrY, jumTitik)
19
20 g.drawPolygon (poly1);
21 int xValues2[] = {70,90,100,80,70,65,60};
22 int yValues2[] = {100,100,110,110,130,110,90};
23 g.drawPolyline (xValues2, yValues2, 7);
24
25 int xValues3[] = {120,140,150,190};
26 int yValues3[] = {40,70,80,60};
27 g.fillPolygon (xValues3, yValues3, 4);
28
29 Polygon poly2 = new Polygon();
30 poly2.addPoint (220,100);
31 poly2.addPoint (175,150);
32 poly2.addPoint (270,150);
33 g.fillPolygon (poly2);
34 }
35
36 public static void main (String args[]) {
37
38 DrawPolygons test = new DrawPolygons();
39 test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
40 }
41
42}
Tidak ada komentar:
Posting Komentar