
import java.awt.*;
import marimba.channel.*;
import marimba.gui.*;

public class ThermometerApplication extends ApplicationPlayerFrame {

public boolean handleEvent(Event evt) {

  if ((evt.id == Event.ACTION_EVENT) && (evt.target instanceof Widget)) {
    Widget targ = (Widget)evt.target;

	 // redirect target to spinbox if user has changed text
	 if (targ instanceof SpinBoxTextWidget)
		targ = ((SpinBoxTextWidget)targ).getOwner();

	 if (targ instanceof ValueWidget) {
	 	int temp = ((ValueWidget)targ).value;
		int newtemp = 0;

		// user has changed value of fahrenheit spinbox
    	if (targ.getName().equals("fahr")) {
			newtemp = (temp - 32) * 5 / 9;
			SpinBoxWidget dest = (SpinBoxWidget)util.getWidget("cels");
			dest.setValue(newtemp);
			util.setValue("slider",String.valueOf(temp));
			return true;

		// user has changed value of celsius spinbox
    	} else if (targ.getName().equals("cels")) { 
			newtemp = temp * 9 / 5 + 32;
			util.setValue("fahr", String.valueOf(newtemp));
			util.setValue("slider",String.valueOf(newtemp));
			return true;

		// user has changed  slider
    	}	else if (targ.getName().equals("slider")) {
			newtemp = (temp - 32) * 5 / 9;
			util.setValue("fahr",String.valueOf(temp));
			util.setValue("cels",String.valueOf(newtemp));
			return true;
		}
	}
  }	
  return super.handleEvent(evt);
}

}

