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.

Sunday, August 15, 2004

Code for a simple HiLo Game in SuperWaba

Here's the promised code. Seems that Blogger doesn't either doesn't like to publish from the FireFox browser, or the original post was too long with the code included.
Sorry about the formatting.... it just doesn't seem to keep track of the indents once it gets published.

import waba.ui.*;
import waba.fx.*;
import waba.util.Random;
import waba.sys.Convert;

public class HiLoGame extends MainWindow {

MenuBar mbar;
String menu[][] = {
{"File", "NewGame", "*Options","*HiScores","Exit"},
{"Help","About", "*Test"}
String guessDialogButtons[] = {"Guess", "Abort Game"};
MessageBox mbAbout;
InputDialog getGuess;
Graphics g;
int target, guess, guessNbr;
int guessCnt;
String resultText, promptText;
Random randomObject;

public HiLoGame() {
highResPrepared = true;
randomObject = new Random();
g = new Graphics(this);
setTitle("HiLo Guessing Game");
mbar = new MenuBar(menu);
mbAbout = new MessageBox("BobSoft",
"Welcome to Bob's HiLo Guessing Game on Palm!|Enjoy..." ); }

public void playGame() {
resultText = "This is your first guess.";
do {
getGuess = new InputDialog(resultText, promptText, "", guessDialogButtons);
guess = Convert.toInt(getGuess.getValue());
resultText = "Your last guess of ("+guess+") was "+calcGuessResult();
promptText = "Enter Guess #"+guessCnt+":";
while (getGuess.getPressedButtonIndex()==0);

public String calcGuessResult() {
String result;
if (guess > target) result = new String("too high.");
else if (guess < target) result = new String("too low.");
else { result = new String("correct on "+guessCnt+" tries!");
initNewGame(); guessCnt = 0;
promptText = "Starting new game... " + promptText;
return result;

public void initNewGame() {
target = randomObject.rand(1,100);
guessCnt = 1;
guess = 0;
promptText = "Enter Guess #"+guessCnt+":";

public void onStart() {

public void onEvent(Event event) {
switch (event.type)
case ControlEvent.WINDOW_CLOSED:
String sel = null;
if ( == mbar)
switch (mbar.getSelectedMenuItem())
case -1: break; // no item selected
case 101: popupModal(mbAbout); break;
case 102: break;
case 001: /*end game*/ playGame();
setTitle("HiLo Guessing Game");
case 004: exit(0); break; // End Program

public void onPaint(Graphics g) {





Post a Comment

<< Home