클릭 할 때 마우스 위치의 위치를 저장하려고합니다. 그런 다음 특정 작업을 수행하기 위해 모션을 분석해야합니다. mouseListener 인터페이스를 사용하고 사용자가 마우스를 클릭하면 사용자가 버튼을 클릭 할 때, i가 움직임을 분석하는 배열을 루프 시도 array.Then 점을 클릭 점을 추가하지만 if(points[i].x<points[i+1].x)
여기에서 널 포인터 예외가 발생하는 것은 코드자바에서 마우스 클릭을 저장
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;
}}}}
에게 인 누구든지 저에 대해 도와주세요. 미리 감사드립니다.
첫 번째 루프는 i + 1 루프에서 사용 중이기 때문에 points.length-1에서 멈춰야합니다. 둘째, 2000 포인트 객체를 배열에 저장 했습니까? – VirtualTroll
@Amine 아니요, 방금 발견했습니다. 지금 변경하겠습니다. 그 점을 지적 해 주셔서 대단히 감사합니다. –