01: // plik 07_TryCatch_2/TestInput.java
02:
03: import javax.swing.*;
04:
05: public class TestInput {
06:
07: public static void main(String[] args) {
08: new TestInput();
09: }
10:
11: public TestInput() {
12:
13: String komunikat = null;
14:
15: while ( true) {
16:
17: String odp = JOptionPane.showInputDialog(null,
18: "Podaj cokolwiek","Pytanie",
19: JOptionPane.QUESTION_MESSAGE
20: );
21:
22: WhatIsIt what = new WhatIsIt(odp);
23:
24: switch (what.getTyp()) {
25: case I:
26: komunikat = "Liczba ca\u0142kowita " +
27: what.getInt();
28: break;
29: case R:
30: komunikat = "Liczba zmiennoprzecinko" +
31: "wa: " + what.getDouble();
32: break;
33: case S:
34: komunikat = "Zwyk\u0142y napis: " +
35: what.getString();
36: break;
37: case E:
38: komunikat = "Pusty napis";
39: break;
40: case N:
41: komunikat = "NULL - koniec programu";
42: break;
43: }
44:
45: JOptionPane.showMessageDialog(
46: null,komunikat,"Wynik",
47: JOptionPane.INFORMATION_MESSAGE
48: );
49:
50: if (what.getTyp() == TYP.N) break;
51: }
52: System.exit(0);
53: }
54: }