// Update coordinates. Car car = cars[selectedIndex]; if(car.getWidth() > car.getHeight()) car.setX(x); else car.setY(y);