I initially wrote a basic implementation of this, under ACM which worked fine. But when I wanted to add some more features to it, I hit roadblocks. ie. a spinner doesn’t seem to work under ACM.
My first crack at it (with ACM):
So I decided to start from scratch without the ACM library and see how to do it. It is interesting to note the ACM Library gives some very nice simple geometric symbol object support… which is superior to the regular Java lib. So a lot of my time was spent figuring how ‘lines’ work without ACM.
Java keyListener not working in Applet…
Another thing that arose was the
keyListener interface, initially I could not get to work at all; the
keyReleased() methods were not called. The culprit had to do with Focus, and I solved it by adding a
requestFocus() call in the
paint() method. That took a quite a bit of hunting to figure out.
My second crack at it (no ACM):
… a few things that could be added / improved:
- Figure out how to get rid of the jittering (ie. find a different method to handle drawing.)
- Offer a
JColorChooserto choose color from, instead of few hard-coded colors.
- Allow user to save/export to image file (ie bitmap).
- Allow user to move the ‘canvas’ around (ie. infinite canvas?).
- Ask for confirmation when the Clear button is clicked.
- redesign keyboard input to allow diagonal moves (two keys pressed at the same time) and add move Diagonal…() functions.