pl/mbogusz3/invaders/view/InvadersView.java
/**
	 * Add swing listeners to actions.
	 */
Add swing listeners to actions.
Add swing listeners to actions .
private void addListeners() {
		InvadersController controller = this.controller;
		menuNewGameItem.addActionListener(event -> controller.putEvent(new InvadersEvent("newGame")));
		menuQuitItem.addActionListener(event -> {
			controller.putEvent(new InvadersEvent("exitGame"));
			closeView();
		});
		frame.addKeyListener(new KeyListener() {
			public void keyTyped(KeyEvent event) {}
			public void keyPressed(KeyEvent event) {
				controller.putEvent(new InvadersEvent("keyDown") {{
					payload.put("keyCode", Integer.toString(event.getKeyCode()));
				}});
			}
			public void keyReleased(KeyEvent event) {
				controller.putEvent(new InvadersEvent("keyUp") {{
					payload.put("keyCode", Integer.toString(event.getKeyCode()));
				}});
			}
		});
		frame.addComponentListener(new ComponentAdapter() {
			@Override
			public void componentResized(ComponentEvent e) {
				controller.putEvent(new InvadersEvent("windowResized"));
				super.componentResized(e);
			}
		});
		frame.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent event) {
				controller.putEvent(new InvadersEvent("exitGame"));
				closeView();
			}
		});
	}
private void addListeners ( ) { InvadersController controller = this . controller ; menuNewGameItem . addActionListener ( event -> controller . putEvent ( new InvadersEvent ( "newGame" ) ) ) ; menuQuitItem . addActionListener ( event -> { controller . putEvent ( new InvadersEvent ( "exitGame" ) ) ; closeView ( ) ; } ) ; frame . addKeyListener ( new KeyListener ( ) { public void keyTyped ( KeyEvent event ) { } public void keyPressed ( KeyEvent event ) { controller . putEvent ( new InvadersEvent ( "keyDown" ) { { payload . put ( "keyCode" , Integer . toString ( event . getKeyCode ( ) ) ) ; } } ) ; } public void keyReleased ( KeyEvent event ) { controller . putEvent ( new InvadersEvent ( "keyUp" ) { { payload . put ( "keyCode" , Integer . toString ( event . getKeyCode ( ) ) ) ; } } ) ; } } ) ; frame . addComponentListener ( new ComponentAdapter ( ) { @ Override public void componentResized ( ComponentEvent e ) { controller . putEvent ( new InvadersEvent ( "windowResized" ) ) ; super . componentResized ( e ) ; } } ) ; frame . addWindowListener ( new WindowAdapter ( ) { @ Override public void windowClosing ( WindowEvent event ) { controller . putEvent ( new InvadersEvent ( "exitGame" ) ) ; closeView ( ) ; } } ) ; }
Add swing listeners to actions.
Add swing listeners to actions .