我想保存鼠標位置的位置 - 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