Obliczenia brydżowe (Java ME)
Jacek Kowalski
2015-08-16 67d931ba96c0e37f439940809813c5179b139bb5
src/brydz/BrydzForm.java
@@ -1,9 +1,18 @@
/*
 * Copyright (c) 2012, Jacek Kowalski (http://jacekk.info)
 * Wszystkie prawa zastrzeżone
 *
 * Licencja w pliku BSD-3.txt
 */
package brydz;
import javax.microedition.lcdui.*;
public class BrydzForm extends Form implements CommandListener, ItemStateListener {
    protected BrydzMIDlet midlet;
    protected BrydzPomocForm help = null;
    protected BrydzPomocForm about = null;
    
    protected TextField kontraktField;
    protected ChoiceGroup kontraktChoice;
@@ -33,8 +42,10 @@
        this.kontraChoice.append("rektr.", null);
        
        this.partiaChoice = new ChoiceGroup(null, ChoiceGroup.EXCLUSIVE);
        this.partiaChoice.append("przed", null);
        this.partiaChoice.append("po", null);
        this.partiaChoice.append("przed / przed", null);
        this.partiaChoice.append("przed / po", null);
        this.partiaChoice.append("po / przed", null);
        this.partiaChoice.append("po / po", null);
        
        this.punktyField = new TextField("PC:", null, 2, TextField.NUMERIC);
        this.lewyField = new TextField("Lew:", null, 2, TextField.NUMERIC);
@@ -49,24 +60,46 @@
        this.append(this.lewyField);
        this.append(this.resultText);
        
        setItemStateListener(this);
        setCommandListener(this);
        addCommand(new Command("Wyczyść", Command.OK, 1));
        addCommand(new Command("Wyjście", Command.EXIT, 1));
        this.addCommand(new Command("Wyczyść", Command.BACK, 1));
        this.addCommand(new Command("Pomoc", Command.HELP, 2));
        this.addCommand(new Command("O programie", Command.HELP, 3));
        this.addCommand(new Command("Wyjście", Command.EXIT, 4));
        this.setItemStateListener(this);
        this.setCommandListener(this);
    }
    
    public void commandAction(Command command, Displayable displayable) {
        if (command.getCommandType() == Command.OK) {
            this.kontraktField.setString(null);
            this.kontraktChoice.setSelectedIndex(0, true);
            this.kontraChoice.setSelectedIndex(0, true);
            this.partiaChoice.setSelectedIndex(0, true);
            this.punktyField.setString(null);
            this.lewyField.setString(null);
            this.resultText.setText("Podaj wszystkie dane.");
        }
        else if (command.getCommandType() == Command.EXIT) {
            this.midlet.destroyApp(true);
        switch(command.getCommandType()) {
            case Command.EXIT:
                this.midlet.destroyApp(true);
            break;
            case Command.CANCEL:
            case Command.BACK:
                this.kontraktField.setString(null);
                this.kontraktChoice.setSelectedIndex(0, true);
                this.kontraChoice.setSelectedIndex(0, true);
                this.partiaChoice.setSelectedIndex(0, true);
                this.punktyField.setString(null);
                this.lewyField.setString(null);
                this.resultText.setText("Podaj wszystkie dane.");
                this.midlet.display.setCurrentItem(this.kontraktField);
            break;
            case Command.HELP:
                if(command.getPriority() == 2) {
                    if(this.help == null) {
                        this.help = new BrydzPomocForm(this.midlet, this, false);
                    }
                    this.midlet.display.setCurrent(this.help);
                }
                else if(command.getPriority() == 3) {
                    if(this.about == null) {
                        this.about = new BrydzPomocForm(this.midlet, this, true);
                    }
                    this.midlet.display.setCurrent(this.about);
                }
            break;
        }
    }
    
@@ -87,9 +120,7 @@
        }
        
        BrydzWynik wynik;
        String data = "";
        if( kontrakt < 0  || kontrakt > 7 ) {
            this.resultText.setText("Niepoprawny kontrakt.");
            return;
@@ -105,7 +136,7 @@
            return;
        }
        
        if( partia != 0 && partia != 1) {
        if( partia < 0 || partia > 3) {
            this.resultText.setText("Niepoprawna informacja o partii.");
            return;
        }