【发布时间】:2014-04-30 21:59:22
【问题描述】:
我正在编写一个 2D 程序。在我的paintComponent 上,我创建了一个弧。
public class Board extends Panel{
protected void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D graphics2d = (Graphics2D)g;
int x = MouseInfo.getPointerInfo().getLocation().x;//set mouses current position
int y = MouseInfo.getPointerInfo().getLocation().y;
graphics2d.setStroke(wideStroke);
graphics2d.draw(new Arc2D.Double(200, 200, 100, 100, ?, 180, Arc2D.OPEN));
}
}
我主要使用Thread 来更新图表。 ? 的位置是起始角度。每次我改变它时,圆弧都会像半个车轮一样移动。是否可以让弧线运动跟随鼠标?例如? = 270
我将如何做到这一点? (对不起我的绘画技巧不好!)
【问题讨论】:
-
类似this FYI-MouseInfo 我们不是一个好的选择,MouseMotionListener 可能是一个更好的选择
-
@MadProgrammer。将其更改为 MouseMotionListener 不是问题。
标签: java graphics mouse paintcomponent pane