
{filelink=9431}
import java.awt.Graphics;
import java.awt.Polygon;
import javax.swing.*;
public class GEOPoly extends JPanel
{
public void paintComponent( Graphics g )
{
super.paintComponent( g );
// Dessiner un Polygone
int xValues[] = { 20, 40, 50, 30, 20, 15 };
int yValues[] = { 50, 50, 60, 80, 80, 60 };
Polygon polygon1 = new Polygon( xValues, yValues, 6 );
g.drawPolygon( polygon1 );
// Dessiner un Polyligne
int xValues2[] = { 70, 90, 100, 80, 70, 65, 60 };
int yValues2[] = { 100, 100, 110, 110, 130, 110, 90 };
g.drawPolyline( xValues2, yValues2, 7 );
}
// Fonction principale
public static void main (String[] args)
{
JFrame frame=new JFrame("Polygone et Polyligne") ;
JPanel policePanel=new GEOPoly();
frame.add(policePanel);
frame.setSize(300,200);
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}