import java.awt.Point;import java.util.ArrayList;public class CropPoint { ArrayList<Point> points; public static void main(String[] args) { CropPoint a = new CropPoint(); a.run(); } public CropPoint(){ points = new ArrayList<Point>(); } public void run(){ points.add(new Point()); points.get(0).setLocation(1.0, 1.5); points.add(new Point()); points.get(1).setLocation(0.0, 1.5); points.add(new Point()); points.get(2).setLocation(0.0, 1.5); points.add(new Point()); points.get(3).setLocation(0.0, 1.5); System.out.println("Points before cropping"); for (Point p : points){ System.out.println("x: "+p.getX()+"\ty: "+p.getY()); } Crop(points.get(1), points.get(2)); System.out.println("Points after cropping"); for (Point p : points){ System.out.println("x: "+p.getX()+"\ty: "+p.getY()); } } private void Crop(Point p1, Point p2){ if (p1.getX() == p2.getX() && p1.getY() == p2.getY()){ for (int i = 0; i < points.size(); i++){ if (points.get(i) != p1){ points.remove(i); i = 0; } } } else if (p1.getX() == p2.getX()){ for (int i = 0; i < points.size(); i++){ if (points.get(i).getX() != p1.getX()){ points.remove(i); i = 0; } } } else if (p1.getY() == p2.getY()){ for (int i = 0; i < points.size(); i++){ if (points.get(i).getY() != p1.getY()){ points.remove(i); i = 0; } } } else{ System.out.println("Error input data"); } }}
Comments