I generated and exported the puzzles by using the sudoku solver found at http://sudoku.sourceforge.net/. You can do the same to add new puzzles—simply export the generated puzzles in XML format, and cut the actual puzzle text from the middle and paste it into a string in the Puzzles class, adding '|' separators between rows. An obvious next logical addition to the app would be to read the puzzles directly from an external file in the original XML format.

The Puzzle class handles parsing of the puzzle definition string and holds the current state of the guesses. Any alternate formats would be handled here. Eventually, this class should handle saving and loading of puzzle solution states.

Ironically, this simple class is where I kept running into the sneaky Java 5 trap. At one point, I introduced a couple of String calls to trim the definition strings. This innocuous method:

test = test.replace("|", "");

was actually added in Java 5, so it and others like it will need to be avoided.

Testing It Out

The quickest way to see the game running is to build and run the sudoku-se under Eclipse. It will run as a default Java Application run configuration. Use the keyboard to navigate and test out the game logic and rendering.

To see the game running on the phone, build the sudoku-xlet project under Eclipse. Then run the two scripts: mkdist to build the jar and dist dir, and tophone to copy the directory tree to the phone's SD. (You will need to adjust the paths in this second script for your machine and SD volume name). Plug the SD into the phone, select My Applications, and play Sudoku!

If your Xlet won't start at all on the phone, it is most like caused by an unresolved symbol (like one in the Java 5 JRE), or that the compiler is set to level 5 Java.

Conclusion

Java ME has come a long way since the early days. The latest CDC specs really cover a lot of ground, and SavaJe provides an incredibly rich platform. It's almost like a desktop in your hand. So many possible applications, so little time.

This is the first real Java ME app that I've written, and see how easy it was? Let me know if you see anything that I really botched, or of course if you have any suggestions. I know that there are quite a few fun things to add to this Sudoku game. You can coordinate any additions at http://code.google.com/p/sudoku-xlet/.

About the Author

Carl Quinn is a Software Engineer at Google [google.com]. He focuses primarily on Java infrastructure, libraries, and development tools. He can be reached at carl.quinn@gmail.com. He also co-hosts The Java Posse, a podcast devoted to Java news and the Java community, which can be found at http://javaposse.com or via the Google group http://groups.google.com/group/javaposse.