////// MySensorListener////// import josx.platform.rcx.SensorListener; import josx.platform.rcx.Sensor; /** * Public class MySensorListener Version 1.0 * @author Karl Gustav Sterneberg, Romain Barrallon, Victor Contreras */ public class MySensorListener implements SensorListener { /** * Constructor. * @param r the robot on which the sensor needing this MySensorListener is placed. */ public MySensorListener(Robot r) { robot = r; } /** * Informed by sensor when sensor's state changed. If sensor pressed, invokes method * sensorTouched upon robot. * @param source the sensor which state has changed. * @param oldValue the old value of the sensor's state. * @param newValue the new value of the sensor's state. */ public void stateChanged(Sensor source, int oldValue, int newValue) { if (newValue == 1) robot.sensorTouched(source); } /** * The robot on which the sensor needing this MySensorListener is placed. */ private Robot robot; }