Class Controller

  • All Implemented Interfaces:
    java.awt.event.ActionListener, java.awt.event.KeyListener, java.util.EventListener

    public class Controller
    extends java.lang.Object
    implements java.awt.event.ActionListener, java.awt.event.KeyListener
    The controller takes care of the input events and reacts on those events by manipulating the view and updates the model.
    Author:
    dmlux, modified by I. Schumacher and I. Traupe, modified by Gruppe 175 (Moritz Henseleit, Ruben Meyer)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Game game
      The game as model that is connected to this controller
      private View view
      The view that is connected to this controller
    • Constructor Summary

      Constructors 
      Constructor Description
      Controller​(View view)
      The constructor expects a view to construct itself.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void actionPerformed​(java.awt.event.ActionEvent e)
      If the user clicks any button this ActionListener will get called.
      private void assignActionListener()
      The controller gets all buttons out of the view with this method and adds this controller as an action listener.
      private void assignKeyListener()
      With this method the controller adds himself as a KeyListener.
      void keyPressed​(java.awt.event.KeyEvent e)
      This method will be called, after a key was pressed down.
      void keyReleased​(java.awt.event.KeyEvent e)
      This method will be called, after a key was released.
      void keyTyped​(java.awt.event.KeyEvent e)
      This method will be called, after a key was typed.
      void toPlayground()
      This method switches the view to the FieldView which will display the playground.
      void toStartScreen​(int score)
      This method switches the view to the StartScreen view.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • game

        private Game game
        The game as model that is connected to this controller
      • view

        private View view
        The view that is connected to this controller
    • Constructor Detail

      • Controller

        public Controller​(View view)
        The constructor expects a view to construct itself.
        Parameters:
        view - The view that is connected to this controller
    • Method Detail

      • assignActionListener

        private void assignActionListener()
        The controller gets all buttons out of the view with this method and adds this controller as an action listener. Every time the user pushed a button the action listener (this controller) gets an action event.
      • assignKeyListener

        private void assignKeyListener()
        With this method the controller adds himself as a KeyListener. Every time the user pushed a key the KeyListener (this controller) gets an KeyEvent.
      • actionPerformed

        public void actionPerformed​(java.awt.event.ActionEvent e)
        If the user clicks any button this ActionListener will get called. The method will get an ActionEvent e which held the source of this event.
        Specified by:
        actionPerformed in interface java.awt.event.ActionListener
      • keyTyped

        public void keyTyped​(java.awt.event.KeyEvent e)
        This method will be called, after a key was typed. This means, that the key was pressed and released, before this method get called.
        Specified by:
        keyTyped in interface java.awt.event.KeyListener
        Parameters:
        e - The key event
      • keyPressed

        public void keyPressed​(java.awt.event.KeyEvent e)
        This method will be called, after a key was pressed down.
        Specified by:
        keyPressed in interface java.awt.event.KeyListener
        Parameters:
        e - The key event
      • keyReleased

        public void keyReleased​(java.awt.event.KeyEvent e)
        This method will be called, after a key was released.
        Specified by:
        keyReleased in interface java.awt.event.KeyListener
        Parameters:
        e - The key event
      • toStartScreen

        public void toStartScreen​(int score)
        This method switches the view to the StartScreen view.
        Parameters:
        score - The player score
      • toPlayground

        public void toPlayground()
        This method switches the view to the FieldView which will display the playground.