Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Berkas: ContohPoligon.java
- import java.awt.*;
- public class ContohPoligon extends Frame {
- public static void main(String[] args) {
- ContohPoligon apl =
- new ContohPoligon();
- }
- public ContohPoligon() {
- super("Contoh Poligon");
- setSize(350, 200);
- CanvasKu kanvas = new CanvasKu();
- add(kanvas);
- show();
- }
- }
- class CanvasKu extends Canvas {
- public void paint(Graphics g) {
- int x[] = {10, 250, 50, 70};
- int y[] = {10, 70, 130, 55};
- int jumlah = x.length;
- g.drawPolyline(x, y, jumlah);
- for(int i=0; i<x.length; i++) {
- x[i] += 50;
- y[i] += 20;
- }
- g.drawPolygon(x, y, jumlah);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement