import java.awt.Color
import javax.swing.JPanel
import com.github.oetzi.echo.Behaviour
import com.github.oetzi.echo.EventSource

package display {
	class ColorPanel extends JPanel {
		def setBackground(color : Behaviour[Color]) {
			new Observer(color).each(event => super.setBackground(event))	
		}
	}
	
	class Observer[T](val behaviour : Behaviour[T]) extends EventSource[T] {
		new Thread(new Runnable() {
			def run() {
				var last = null
				while (true) {
					val now = behaviour.now
					if (last != now) {
						Observer.this.occur(now)
					}
					Thread.sleep(20)
				}
			}
		}).start()
	}
}
import java.awt.Color
import javax.swing.JPanel
import com.github.oetzi.echo.Behaviour

package display {
	class ColorPanel extends JPanel {
		def setBackground(color : Behaviour[Color]) {
			new Thread(new Runnable {
				def run() {
					var last = null
					while (true) {
						val now = color.now
						if (last != now) {
							ColorPanel.super.setBackground(now)
						}
						Thread.sleep(20)
					}
				}
			}).start()	
		}
	}
	
	class Observer[T] extends EventSource[T] {
		//this will replace the code in setBackground
	}
}
--- 
+++ 
@@ -1,26 +1,27 @@
 import java.awt.Color
 import javax.swing.JPanel
 import com.github.oetzi.echo.Behaviour
+import com.github.oetzi.echo.EventSource
 
 package display {
 	class ColorPanel extends JPanel {
 		def setBackground(color : Behaviour[Color]) {
-			new Thread(new Runnable {
-				def run() {
-					var last = null
-					while (true) {
-						val now = color.now
-						if (last != now) {
-							ColorPanel.super.setBackground(now)
-						}
-						Thread.sleep(20)
-					}
-				}
-			}).start()	
+			new Observer(color).each(event => super.setBackground(event))	
 		}
 	}
 	
-	class Observer[T] extends EventSource[T] {
-		//this will replace the code in setBackground
+	class Observer[T](val behaviour : Behaviour[T]) extends EventSource[T] {
+		new Thread(new Runnable() {
+			def run() {
+				var last = null
+				while (true) {
+					val now = behaviour.now
+					if (last != now) {
+						Observer.this.occur(now)
+					}
+					Thread.sleep(20)
+				}
+			}
+		}).start()
 	}
 }
Implement prototype observer in the color example
