GUI code
There was some time required to get the GUI running. However, when I did the game ran, but there were some issues. For instance, you can scale the window containing puzzle, but that just mucks up the contents. The puzzle is not scaled well initially either, and a line seems to be missing on the right hand side.
I don't expect to interact with a Viewer
. Maybe with a View
, but a Viewer
sounds rather passive.
There are dual calls to drawGrid
that aren't explained at all. I don't see why those are necessary.
I presume the squares are 100 pixels in size or so, but there is a lot of repetition of the value 100. The value 100 should probably be a constant, but generally I'd already use a squareEdgeSize
variable for that. At least you did make sure that the value is not repeated in the canvas code, so that's OK.
You are using a MouseListener
with unimplemented methods. However, in that case you might want to have a look at a MouseAdapter
instead that provides default implementations, cleaning up your listener interface.
When you look at the drawRectangle
you can see that you specifically have to calculate x + 100
, while the original method of drawing in Java uses a width
. So you are calculating a second x
using the width only to reverse that later.
Your methods are not symmetric. You have a drawGrid()
that doesn't take any arguments, and many other draw
methods that do. That kind of inconsistencies are also seen in the whitespace and such. It makes the code less clean and harder to read.
Both the constructor of the viewer and another method draw the grid, and make the same decision which one to draw. This goes against DRY principles.