import java.awt.*;
import javax.swing.*;

public class TestPolyline extends JFrame {
public TestPolyline() {
add(new PolylinePanel());
}
public static void main(String[] args) {
TestPolyline frame = new TestPolyline();
frame.setTitle("TestPolyline");
frame.setSize(300,200);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}

static class PolylinePanel extends JPanel {
private Polygon p = new Polygon();

public PolylinePanel() {

}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
p.addPoint(getWidth() / 2, getHeight() / 2);
p.addPoint(50, 50);
g.drawPolyline(p.xpoints, p.ypoints, p.npoints);
g.drawString("" + (p.xpoints).length, 50, 50);
}
}
}


import java.awt.*;
import javax.swing.*;

public class TestPolyline extends JFrame {
public TestPolyline() {
add(new PolylinePanel());
}
public static void main(String[] args) {
TestPolyline frame = new TestPolyline();
frame.setTitle("TestPolyline");
frame.setSize(300,200);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}

static class PolylinePanel extends JPanel {
private Polygon p = new Polygon();

public PolylinePanel() {
p.addPoint(getWidth() / 2, getHeight() / 2);
p.addPoint(50, 50);
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawPolyline(p.xpoints, p.ypoints, p.npoints);
g.drawString("" + (p.xpoints).length, 50, 50);
}
}
}