// plik 07_TryCatch_2/TestInput.java

import javax.swing.*;

public class TestInput {

    public static void main(String[] args) {
        new TestInput();
    }

    public TestInput() {

        String   komunikat = null;

        while ( true) {

            String odp = JOptionPane.showInputDialog(null,
                      "Podaj cokolwiek","Pytanie",
                      JOptionPane.QUESTION_MESSAGE
                  );

            WhatIsIt what = new WhatIsIt(odp);

            switch (what.getTyp()) {
                case I:
                    komunikat = "Liczba ca\u0142kowita " +
                        what.getInt();
                    break;
                case R:
                    komunikat = "Liczba zmiennoprzecinko" +
                        "wa: " + what.getDouble();
                    break;
                case S:
                    komunikat = "Zwyk\u0142y napis: " +
                        what.getString();
                    break;
                case E:
                    komunikat = "Pusty napis";
                    break;
                case N:
                    komunikat = "NULL - koniec programu";
                    break;
            }

            JOptionPane.showMessageDialog(
                null,komunikat,"Wynik",
                JOptionPane.INFORMATION_MESSAGE
            );

            if (what.getTyp() == TYP.N) break;
        }
        System.exit(0);
    }
}
