Journey into SuperWaba

Ever wonder what it takes to write programs for your PDA? I did, and so now I am beginning a journey to try my hand at writing something for the PalmOS. SuperWaba, a variation of Java for the PDA, is my language of choice. And I'm a novice, which makes it all the more unpredictable. Hope you'll come along for the ride! Note: You can read multiple posts on one page if you click on an archive link.

Thursday, August 19, 2004

Another Way to Code the HiLo Game

After running into the problems with popupBlockingModal() in the main window constructor and main window onStart() method, I started looking further into the alternate way of handling screen contents.

The basic idea (see the sample code for ContainerSwitch included with the SuperWaba download) is that you can extend the Container class with your class that sort of reflects one screen of activity and controls for your program.

Think of the hilo game. You might have a welcome screen and a main activity screen. You can code this as one class for each screen, where the classes extend Container. Then you can swap back and forth from the MainWindow to make whichever container class current and visible. Actually, visible is different than current, but if you use the Window.swap() method, the window you swap into place becomes visible automatically.

Note also that you can always reference the MainWindow with the static method:

In my code, I have three classes. I chose not to try to let the main program class contain any screen contents. Those were all done via separate classes that are extentions of Container. This is slightly different from the ContainerSwitch sample code which puts controls on the main window and swaps other containers in and out from there. I suppose I could have done something like that and saved a Class, but for now I wanted to do what was easier for me to keep in my head.

I've also used public static members for the main window class. If you are an expert in Java and SuperWaba, I'm sure my code makes it really obvious that I'm not comfortable with scope and encapsulation yet, especially in this new sort of GUI/event world I'm exploring. But hopefully that will become clearer to me and cleaner in the code as time passes.

As long posts gave me a problem before, I'll use a separate post for the code I've got so far with containers representing screens. There's absolutely no functioning guessing code for the guts of the game, but that shouldn't be too hard to add after the fact.

See ya!


Post a Comment

<< Home