- Java Swing
- General Structure of Java Program
- Swing implementation
- Download Snake and Source Code
The planned parts of this Series:
I will start with Swing.
documentation of Swing is quite good, but I do think that the api is overly complex and in some parts not completely thought through.
The program is structured using the mvc pattern. The model is not really important to the guis, so I will not describe it, if it interests you feel free to view the source.
The important controller is the AbstractGameController as it handles the logic of the game. It also reports changes of the game field to the gui and reads input from the IInputController interface. It does not contain an actual game loop (as android did not allow this to be realized easily) but can be easily extended. It also does not run in its own thread (again, because of android), but this too may be realized in the extended controller.
My key for Visual Paradigm for UML expired, so I used ArgoUML to create the following UML diagram. Sadly, I could not find functions I needed (such as copying a class or showing classes inside packages). I searched the web, but could not find any help, so I finished it with gimp…
I do know that it does not look very good, but hey, it’s snake (in swing, which I think never *really* looks good, even when I do put an effort in it). The Android version will (well, already does) look nicer, I promise.
Snake with Swing Gui [22.92 kB]
Snake with Swing Gui Source code [21.9 kB]
The second part is Android: Snake with different Guis