Class UserInterface
- java.lang.Object
-
- 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>aButtonsprivate GameEngineaEngineprivate javax.swing.JTextFieldaEntryFieldprivate javax.swing.JLabelaImageprivate javax.swing.JTextAreaaLogprivate javax.swing.JFrameaMyFrameprivate javax.swing.JPanelaPanelButtons
-
Constructor Summary
Constructors Constructor Description UserInterface(GameEngine pGameEngine)Construct a UserInterface.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactionPerformed(java.awt.event.ActionEvent pE)Actionlistener interface for entry textfield.private voidcreateGUI()Set up graphical user interface.voiddisableButtons()voidenable(boolean pOnOff)Enable or disable input in the input field.voidprint(java.lang.String pText)Print out some text into the text area.voidprintln(java.lang.String pText)Print out some text into the text area, followed by a line break.private voidprocessCommand()A command has been entered.voidshowImage(java.lang.String pImageName)Show an image file in the interface.
-
-
-
Field Detail
-
aEngine
private GameEngine aEngine
-
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
-
aPanelButtons
private javax.swing.JPanel aPanelButtons
-
-
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:
actionPerformedin interfacejava.awt.event.ActionListener
-
disableButtons
public void disableButtons()
-
processCommand
private void processCommand()
A command has been entered. Read the command and do whatever is necessary to process it.
-
-