java - when clicked print coordinates from Points in array -
i want print out x , y coordinates 3 points in array. when clicked on jframe, coordinates of click need go first point p1, sec click sec point p2 , 3rd click p3. code:
public void mousepressed(mouseevent e) { point[] points = new point[3]; p1 = points[0] = e.getpoint(); p2 = points[1] = e.getpoint(); p3 = points[2] = e.getpoint(); system.out.println(p1 + p2 + p3);
what doing wrong?
you need set points outside of moussepressed
point[] points=new point[3]; int i=0; public void mousepressed(mouseevent e){ if(i==0){ points[0]=e.getpoint(); }else if(i==1){ points[1]=e.getpoint(); }else if(i==2){ points[2]=e.getpoint(); } i++; }
java arrays point
No comments:
Post a Comment