我试图在绘画部分获得光标的点,并只画一个椭圆。虽然没有运气!小程序绘画
public void paint(Graphics g){
Point ComponentPoint = PaintPanel.getLocationOnScreen();
Point CursorPoint= MouseInfo.getPointerInfo().getLocation(); //gets cursor point
int ComPX = ComponentPoint.x;
int ComPY = ComponentPoint.y;
int CurPX = CursorPoint.x;
int CurPY = CursorPoint.y;
int FinalX = CurPX - ComPX;
int FinalY = CurPY - ComPY;
g.drawOval(FinalX, FinalY, 20, 20);
}
private void PaintPanelMouseDragged(java.awt.event.MouseEvent evt) {
//when mouse is moved over paintpanel
//PaintPanel.repaint();
not working
}
这是不需涂漆方法,图像:
http://i.stack.imgur.com/VOyhr.png
考虑创建并发布一个小的*几乎*工作的例子,你最好的尝试解决方案,换句话说,[sscce](http://sscce.org)。 – 2013-03-24 00:51:20
随着我发布它没有显示任何东西:/我尝试了别的东西,它摆脱了一切,但画了椭圆形。 – bob 2013-03-24 00:57:21
很难知道如何在没有上下文的情况下发布一小段代码。这就是为什么我要求你通过创建一个非常小但可编译和可运行的程序来提供一些上下文。 – 2013-03-24 00:59:11