Java 怎么画虚线

2019年8月20日22:29:37Java 怎么画虚线已关闭评论 226 469字阅读1分33秒

1.简介

Java 怎么画虚线?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */


import java.awt.BasicStroke;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Stroke;

public class Main {
    public static void drawDashedLine(Graphics g, double x1, double y1,
            double x2, double y2) {

        
        Graphics2D g2d = (Graphics2D) g.create();

        Stroke dashed = new BasicStroke(3, BasicStroke.CAP_BUTT,
                BasicStroke.JOIN_BEVEL, 0, new float[] { 9 }, 0);
        g2d.setStroke(dashed);
        g2d.drawLine((int) x1, (int) y1, (int) x2, (int) y2);

        
        g2d.dispose();
    }
}

 
编程十万个怎么办