Gestione di più eventi in parallelo

Modificare il programma realizzato in classe in modo che gestisca anche i 2 sensori restanti: il TouchSensor e l’UltrasonicSensor e visualizzi i valori sulle righe 2 e 3.

import lejos.nxt.Button;
import lejos.nxt.LCD;
import lejos.nxt.LightSensor;
import lejos.nxt.SensorPort;
import lejos.nxt.SensorPortListener;
import lejos.nxt.SoundSensor;

public class SensoriInsieme {

	LightSensor ls;
	SoundSensor ss;

	private class AscoltaLuce implements SensorPortListener {

		@Override
		public void stateChanged(SensorPort aSource, int aOldValue, int aNewValue) {
			int value = ls.readValue();
			LCD.drawString("LS=" + value + "   ", 0, 0);
		}

	}

	private class AscoltaSuono implements SensorPortListener {

		@Override
		public void stateChanged(SensorPort aSource, int aOldValue, int aNewValue) {
			int value = ss.readValue();
			LCD.drawString("SS=" + value + "   ", 0, 1);
		}

	}

	public SensoriInsieme() {
		ls = new LightSensor(SensorPort.S1);
		ss = new SoundSensor(SensorPort.S2);
		SensorPort.S1.addSensorPortListener(new AscoltaLuce());
		SensorPort.S2.addSensorPortListener(new AscoltaSuono());
	}

	public static void main(String[] args) {
		new SensoriInsieme();
		Button.ESCAPE.waitForPressAndRelease();
	}

}