Class UserInterface

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

    public class UserInterface
    extends java.lang.Object
    implements java.awt.event.ActionListener
    This class implements a simple graphical user interface with a text entry area, a text output area and an optional image.
    Version:
    1.0 (Jan 2003) DB edited (2019)
    Author:
    Michael Kolling
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.HashMap<java.lang.String,​javax.swing.JButton> aButtons  
      private GameEngine aEngine  
      private javax.swing.JTextField aEntryField  
      private javax.swing.JLabel aImage  
      private javax.swing.JTextArea aLog  
      private javax.swing.JFrame aMyFrame  
      private javax.swing.JPanel aPanelButtons  
    • Constructor Summary

      Constructors 
      Constructor Description
      UserInterface​(GameEngine pGameEngine)
      Construct a UserInterface.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void actionPerformed​(java.awt.event.ActionEvent pE)
      Actionlistener interface for entry textfield.
      private void createGUI()
      Set up graphical user interface.
      void disableButtons()  
      void enable​(boolean pOnOff)
      Enable or disable input in the input field.
      void print​(java.lang.String pText)
      Print out some text into the text area.
      void println​(java.lang.String pText)
      Print out some text into the text area, followed by a line break.
      private void processCommand()
      A command has been entered.
      void showImage​(java.lang.String pImageName)
      Show an image file in the interface.
      • Methods inherited from class java.lang.Object

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

      • aMyFrame

        private javax.swing.JFrame aMyFrame
      • aEntryField

        private javax.swing.JTextField aEntryField
      • aLog

        private javax.swing.JTextArea aLog
      • aImage

        private javax.swing.JLabel aImage
      • aButtons

        private java.util.HashMap<java.lang.String,​javax.swing.JButton> aButtons
    • Constructor Detail

      • UserInterface

        public UserInterface​(GameEngine pGameEngine)
        Construct a UserInterface. As a parameter, a Game Engine (an object processing and executing the game commands) is needed.
        Parameters:
        gameEngine - The GameEngine object implementing the game logic.
    • Method Detail

      • print

        public void print​(java.lang.String pText)
        Print out some text into the text area.
      • println

        public void println​(java.lang.String pText)
        Print out some text into the text area, followed by a line break.
      • showImage

        public void showImage​(java.lang.String pImageName)
        Show an image file in the interface.
      • enable

        public void enable​(boolean pOnOff)
        Enable or disable input in the input field.
      • createGUI

        private void createGUI()
        Set up graphical user interface.
      • actionPerformed

        public void actionPerformed​(java.awt.event.ActionEvent pE)
        Actionlistener interface for entry textfield.
        Specified by:
        actionPerformed in interface java.awt.event.ActionListener
      • processCommand

        private void processCommand()
        A command has been entered. Read the command and do whatever is necessary to process it.