Java 怎么画虚线

2019年8月20日22:29:37 评论 20

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();
    }
}

 

3.总结

示例代码演示了 Java 怎么画虚线,具体步骤参见示例代码。

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: