我想保存鼠标位置的位置 - click.Then我需要分析它的议案做一个特定的task.I使用mouseListener接口,当用户点击鼠标我添加点击的点array.Then当用户点击一个按钮,我试图遍历阵列来分析所述运动的点,但我得到在if(points[i].x<points[i+1].x)
这里一个零指示字例外是代码保存在java中的鼠标点击
Point points[] = new Point[2000];
int numPoints = 0;
void eventOutput(String eventDescription, MouseEvent e) {
System.out.println(eventDescription+" X= "+e.getX()+" Y= "+e.getY());
//xList.add(new Integer(e.getX()));
//yList.add(new Integer(e.getY()));
points[numPoints] = new Point(e.getX(), e.getY());
++numPoints;
}
for(int i=0;i<points.length;i++)
{
System.out.println("In MOO "+points[i].x);
if(points[i].x<points[i+1].x)
{
xInc=true;
if(points[i].y<points[i+1].y)
{
yInc=true;
}
else if(points[i].y>points[i+1].y)
{
yDec=true;
}
}
else if(points[i].x>points[i+1].x)
{
xDec=true;
if(points[i].y<points[i+1].y)
{
yInc=true;
}
else if(points[i].y>points[i+1].y)
{
yDec=true;
}}}}
任何人都可以请帮我关于这一点。预先感谢
首先,您的循环应停在points.length-1上,因为您正在使用循环i + 1。其次,你确定你在阵列中存储了2000点对象吗? – VirtualTroll 2011-05-13 18:07:54
@Amine不,我刚刚发现,我现在就改变它。非常感谢你指出这一点。 – 2011-05-13 18:13:34