, , , , , , ,

Super Etch A Sketch

After I was finished with all the assignments in CS106A I took a look in the handout 46-practice-final-exam.pdf and immediately took a liking to the 2nd problem: EtchASketch.

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):

EtchASketch Applet: Run
EtchASketch.java (view | download)

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 keyTyped(), keyPressed(), 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):

SuperEtchASketch Applet: Run
SuperEtchASketch.java (view | download)
EtchLine.java (view | download)

… 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 JColorChooser to 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.