Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. package com.kursusinternet.graphics;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5. import java.awt.Graphics2D;
  6. import java.awt.Polygon;
  7.  
  8. import javax.swing.JFrame;
  9. import javax.swing.JPanel;
  10.  
  11. public class GambarSegitiga extends JPanel {
  12.  
  13.     private static final long serialVersionUID = 1L;
  14.  
  15.     public void gambar(Graphics g)
  16.     {
  17.         Graphics2D g2d = (Graphics2D) g;
  18.         int x[] = {50, 200, 350};
  19.         int y[] = {320, 50, 320};
  20.        
  21.         g2d.draw(new Polygon(x,y,x.length));
  22.     }
  23.  
  24.     public void paintComponent(Graphics g) {
  25.         clear(g);
  26.         gambar(g);
  27.     }
  28.  
  29.     protected void clear(Graphics g) {
  30.         super.paintComponent(g);
  31.     }
  32.  
  33.     public static void main(String[] args) {
  34.         GambarSegitiga panelGambar = new GambarSegitiga();
  35.         JFrame frameGambar = new JFrame("Gambar Polyline");
  36.         frameGambar.setSize(400, 400);
  37.         panelGambar.setBackground(Color.white);
  38.         frameGambar.setContentPane(panelGambar);
  39.         frameGambar.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  40.         frameGambar.setVisible(true);
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement