本文介绍了java:Graphics2D版本的折线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好,因此 Graphics2D.draw()
而不是Graphics.drawLine()
和Graphics.drawRectangle()
.
Graphics.drawPolyLine()
是否有类似的升级"?
Is there a similar "upgrade" for Graphics.drawPolyLine()
?
推荐答案
看看 Path2D
.它是一个Shape
,因此应该可以通过Graphics2D.draw()
绘制.
Have a look at Path2D
. It is a Shape
and should thus be able to be drawn through Graphics2D.draw()
.
示例用法:
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);
}
}
这篇关于java:Graphics2D版本的折线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!