Java ME scorecard with vector and multiple input fields/screens

Posted by proximity on Stack Overflow See other posts from Stack Overflow or by proximity
Published on 2010-12-28T10:05:57Z Indexed on 2010/12/28 10:54 UTC
Read the original article Hit count: 228

Filed under:
|

I have made a scorecard with 5 holes, for each a input field (shots), and a image is shown. The input should be saved into a vector and shown on each hole, eg. hole 2: enter shots, underneath it "total shots: 4" (if you have made 4 shots on hole 1). In the end I would need a sum up of all shots, eg.

Hole 1: 4
Hole 2: 3
Hole 3: 2 ...
Total: 17

Could someone please help me with this task?

    {
            f = new Form("Scorecard");
            d = Display.getDisplay(this);
            mTextField = new TextField("Shots:", "", 2, TextField.NUMERIC);
            f.append(mTextField);
            mStatus = new StringItem("Hole 1:", "Par 3, 480m");
            f.append(mStatus);

            try { Image j = Image.createImage("/hole1.png");
            ImageItem ii = new ImageItem("", j, 3, "Hole 1");
            f.append(ii);
            }
            catch (java.io.IOException ioe) {}
            catch (Exception e) {}

        f.addCommand(mBackCommand);
        f.addCommand(mNextCommand);
        f.addCommand(mExitCommand);
        f.setCommandListener(this);

        Display.getDisplay(this).setCurrent(f);
   }

    public void startApp()
    {
        mBackCommand = new Command("Back", Command.BACK, 0);
        mNextCommand = new Command("Next", Command.OK, 1);
        mExitCommand = new Command("Exit", Command.EXIT, 2);
    }

    public void pauseApp() { }

    public void destroyApp(boolean unconditional) {    }

    public void commandAction(Command c, Displayable d) {
        if (c == mExitCommand) {
            destroyApp(true);
            notifyDestroyed();
        }
        else if ( c == mNextCommand) {

// -> go to next hole input! save the mTextField input into a vector.

        }

}

}

------------------------------ Full code --------------------------------- import java.util.; import javax.microedition.midlet.; import javax.microedition.lcdui.*;

public class ScorerMIDlet extends MIDlet implements CommandListener {

private Command mExitCommand, mBackCommand, mNextCommand;
private Display d;
private Form f;
private TextField mTextField;
private Alert a;
private StringItem mHole1;
private int b;

// repeat holeForm for all five holes and add the input into a vector or array. Display the values in the end after asking for todays date and put todays date in top of the list. Make it possible to go back in the form, eg. hole 3 -> hole 2 -> hole 1

public void holeForm(int b) {

        f = new Form("Scorecard");
        d = Display.getDisplay(this);
        mTextField = new TextField("Shots:", "", 2, TextField.NUMERIC);
        f.append(mTextField);
        mHole1 = new StringItem("Hole 1:", "Par 5, 480m");

        f.append(mHole1);

        try { Image j = Image.createImage("/hole1.png");
        ImageItem ii = new ImageItem("", j, 3, "Hole 1");
        f.append(ii);
        }
        catch (java.io.IOException ioe) {}
        catch (Exception e) {}

        // Set date&time in the end
        long now = System.currentTimeMillis();
        DateField df = new DateField("Playing date:", DateField.DATE_TIME);
        df.setDate(new Date(now));
        f.append(df);

    f.addCommand(mBackCommand);
    f.addCommand(mNextCommand);
    f.addCommand(mExitCommand);
    f.setCommandListener(this);

    Display.getDisplay(this).setCurrent(f);

}

public void startApp()
{

    mBackCommand = new Command("Back", Command.BACK, 0);
    mNextCommand = new Command("OK-Next", Command.OK, 1);
    mExitCommand = new Command("Exit", Command.EXIT, 2);
    b = 0;
    holeForm(b);
}

public void pauseApp() {}

public void destroyApp(boolean unconditional) {}

public void commandAction(Command c, Displayable d) {
    if (c == mExitCommand) {
        destroyApp(true);
        notifyDestroyed();
    }
    else if ( c == mNextCommand) {

        holeForm(b);
    }

}

}

© Stack Overflow or respective owner

Related posts about java

Related posts about java-me