Java Swing:绘制曲线 [英] Java Swing: Drawing curved lines

查看:957
本文介绍了Java Swing:绘制曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用Java绘制曲线。一个简单的贝塞尔曲线,(X,Y)开始,(X,Y)结束,曲线数量就足够了。

I'm trying to draw curved lines in Java. A simple bezier curve with an (X,Y) start, an (X,Y) end, and a curve amount would suffice.

我找不到方法在Swing中这样做。如果它不在Swing中,我可以使用一些简单的数学运算吗?我将如何在Swing中实现它?

I can't find a way to do this in Swing. If it's not in Swing, is there some simple math I can use to do it? And how would I implement it in Swing?

编辑:我知道如何通过覆盖绘制(Graphics g)方法绘制形状和线条。

I'm aware of how to draw shapes and lines by overriding the paint(Graphics g) method.

推荐答案

您可以使用Java 2D对象绘制Bézier曲线 Path2D.Double 。只需调用方法 curveTo(float x1,
float y1,
float x2,
float y2,
float x3,
float y3)
并定义3坐标。

You can draw a Bézier curve using the Java 2D Object Path2D.Double. Just call the method curveTo(float x1, float y1, float x2, float y2, float x3, float y3) and define the 3 coordinate.


  • 第一个Bézier控制点

  • 第二个Bézier控制点

  • 最终结束点

这篇关于Java Swing:绘制曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆