Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. // Berkas: ContohPoligon.java
  2.  
  3. import java.awt.*;
  4.  
  5. public class ContohPoligon extends Frame {
  6. public static void main(String[] args) {
  7. ContohPoligon apl =
  8. new ContohPoligon();
  9. }
  10.  
  11. public ContohPoligon() {
  12. super("Contoh Poligon");
  13. setSize(350, 200);
  14.  
  15. CanvasKu kanvas = new CanvasKu();
  16. add(kanvas);
  17.  
  18. show();
  19. }
  20. }
  21.  
  22. class CanvasKu extends Canvas {
  23.  
  24. public void paint(Graphics g) {
  25. int x[] = {10, 250, 50, 70};
  26. int y[] = {10, 70, 130, 55};
  27.  
  28. int jumlah = x.length;
  29. g.drawPolyline(x, y, jumlah);
  30.  
  31. for(int i=0; i<x.length; i++) {
  32. x[i] += 50;
  33. y[i] += 20;
  34. }
  35.  
  36. g.drawPolygon(x, y, jumlah);
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement