import java.awt.event.KeyEvent; import java.util.HashMap; import java.util.Map; public class Controller { private IModel model; private IView view; public Controller(IModel m) { model = m; } public void setView(IView v) { view = v; //create and set the keyboard listener configureKeyBoardListener(); configureButtonListener(); } /** * Creates and sets a keyboard listener for the view * In effect it creates snippets of code as Runnable object, one for each time a key * is typed, pressed and released, only for those that the program needs. *
* In this example, we need to toggle color when user TYPES 'd', make the message * all caps when the user PRESSES 'c' and reverts to the original string when the * user RELEASES 'c'. Thus we create three snippets of code and put them in the appropriate map. * This example shows how to create these snippets of code using lambda functions, a new feature * in Java 8. *
* For more information on Java 8's syntax of lambda expressions, go here: * https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html *
* The above tutorial has specific example for GUI listeners. *
* Last we create our KeyboardListener object, set all its maps and then give it to
* the view.
*/
private void configureKeyBoardListener() {
Map