Instead of tasks 1 and 2, you can realize a graphical user interface in your own project.
Apply also the Observer design pattern in the same way as it has been applied to the ogres and knights game.
To be used in Eclipse, JavaFX has to be installed. See the manual to installing and using JavaFX in Eclipse.
JavaFX is already installed on the computers in CPU, but it's still necessary to do the steps introduced in the second part of the manual.
- Add another button into the window for controlling the ogres and knights game which would serve for deleting the contents of the text field in the window.
- Since the last lecture, in the ogres and knights game, the Observer design pattern is implemented. The Clash class itself plays the role of Subject, while the Observer role is represented by the ClashObserver interface. The EnergyOfWarriors class is the only concrete observer implemented. Create another implementation of the Observer role and the corresponding element into the game window.
- One of the possibilities to handle a button click event in the ogres and knights game was by an anonymous class.
Anonymous classes are a special case of inner classes.
Experiment with further, separate examples of inner classes which are provided with the lecture notes
(besides one class, all other types are provided with no accessibility modifiers, so that you can put each example into one file and compile it):
- In example 1, note all the places an inner class can be created at.
Delete the comment mark in the line for creating instances of the D and C class. Note that if a class is defined within a different range (block), it is unknown outside of it.
- Check what class files have been created during the example 1 compilation. Is there a file there that corresponds to the D class, whose creation is conditional? Will the situation change if you provide a positive parameter to the f() metho call in the main() method?
- Example 2 demonstrates accessing an inner/anonymous class instance using an outer interface.
- Example 3 demonstrates inner/anonymous classes to transfer the functionality into another context. Similarly as with the previous example, this is achieved using an interface defined in the outer context which is implemented by the corresponding inner class. This is exactly how EventHandler is implemented in JavaFX.
- Handling a button click event in the game with ogres and knights was realized also by a method reference and lambda expression. An example that demonstrates using method references and different variants of lambda expressions in general sense is provided to the lecture notes. Try and study all variants (by removing the corresponding comment marks).
vranic at stuba.sk