Java: polyline of graphics2d version?

OK, so a line2d and a rectangle 2D can be used by graphics2d Draw () instead of graphics Drawline() and graphics Drawrectangle() is used

Graphics. Does drawpolyline () have a similar "upgrade"?

Solution

Look at path2d It is a shape, so it should be available through graphics2d Draw()

Usage example:

import java.awt.*;
import java.awt.geom.Path2D;

import javax.swing.*;

public class FrameTestBase extends JFrame {

    public static void main(String args[]) {
        FrameTestBase t = new FrameTestBase();
        t.add(new JComponent() {
            public void paintComponent(Graphics g) {
                Path2D p = new Path2D.Double();
                p.moveTo(15,15);
                p.lineTo(150,75);
                p.lineTo(100,10);
                p.lineTo(10,100);

                ((Graphics2D) g).draw(p);
            }
        });

        t.setDefaultCloSEOperation(EXIT_ON_CLOSE);
        t.setSize(200,200);
        t.setVisible(true);
    }
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>