[英]JFreechart(Java) - How to draw lines that is partially dashed lines and partially solid lines?
[英]Java - How to draw dashed and wavy lines?
我想在Java中繪制虛線和波浪線。 我可以使用Graphics
和g.drawLine()
方法繪制法線。 有沒有一種簡單的方法可以在Graphics2D
或類似Graphics2D
繪制虛線和波浪線?
現在,我使用MouseListener
的坐標繪制線條。 因此它類似於MS Paint。
public void drawDashedLine(Graphics g, int x1, int y1, int x2, int y2){
//creates a copy of the Graphics instance
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(x1, y1, x2, y2);
//gets rid of the copy
g2d.dispose();
}
您可以像這樣創建虛線。
import java.awt.geom.*;
import java.awt.*;
import javax.swing.*;
public class CurveDraw extends JFrame {
public static void main(String[] args) {
CurveDraw frame = new CurveDraw();
frame.setVisible(true);
}
public CurveDraw() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400,400);
}
public void paint(Graphics g) {
QuadCurve2D.Double curve = new QuadCurve2D.Double(50,100,100,170,150,100);
((Graphics2D)g).draw(curve);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.