|
16 | 16 | * Use it to collect numerical input from the user<br> |
17 | 17 | * Or to display a message for the user to read.<br> |
18 | 18 | */ |
19 | | -public class MessageBox { |
20 | | - private static MessageBoxInstance messageBox = new MessageBoxInstance(); |
21 | | - |
22 | | - /** |
23 | | - * Prints a request for a numerical input to the window. <br> |
24 | | - * <b>Example:</b> |
25 | | - * {@code int cookies = MessageBox.askForNumericalInput("How many cookies would you like?");} |
26 | | - * |
27 | | - * @param message |
28 | | - * the text to be displayed |
29 | | - * @return the user input |
30 | | - */ |
31 | | - public static int askForNumericalInput(String message) { |
32 | | - return messageBox.askForNumericalInput(message); |
33 | | - } |
34 | | - |
35 | | - /** |
36 | | - * Prints a request for a text input to the window. <br> |
37 | | - * <b>Example:</b> |
38 | | - * {@code String name = MessageBox.askForTextInput("What is your nickname?");} |
39 | | - * |
40 | | - * @param message |
41 | | - * the text to be displayed |
42 | | - * @return the user input |
43 | | - */ |
44 | | - public static String askForTextInput(String message) { |
45 | | - return messageBox.askForTextInput(message); |
46 | | - } |
47 | | - |
48 | | - /** |
49 | | - * Prints the message to the window. <br> |
50 | | - * <b>Example:</b> {@code MessageBox.showMessage("Girl programmers rule!");} |
51 | | - * |
52 | | - * @param message |
53 | | - * the text to be displayed |
54 | | - */ |
55 | | - public static void showMessage(String message) { |
56 | | - messageBox.showMessage(message); |
57 | | - } |
58 | | - |
59 | | - public static void mock(MessageBoxInstance messageBoxMock) { |
60 | | - messageBox = messageBoxMock; |
61 | | - } |
62 | | - |
63 | | - public static class MessageBoxInstance { |
64 | | - public int askForNumericalInput(String message) { |
65 | | - String input = askForTextInput(message); |
66 | | - return NumberUtils.load(input, 0); |
67 | | - } |
68 | | - |
69 | | - public String askForTextInput(String message) { |
70 | | - return JOptionPane.showInputDialog(message); |
71 | | - } |
72 | | - |
73 | | - public void showMessage(String message) { |
74 | | - JOptionPane.showMessageDialog(null, message); |
75 | | - } |
76 | | - } |
| 19 | +public class MessageBox |
| 20 | +{ |
| 21 | + private static MessageBoxInstance messageBox = new MessageBoxInstance(); |
| 22 | + /** |
| 23 | + * Prints a request for a numerical input to the window. <br> |
| 24 | + * <b>Example:</b> |
| 25 | + * {@code int cookies = MessageBox.askForNumericalInput("How many cookies would you like?");} |
| 26 | + * |
| 27 | + * @param message |
| 28 | + * the text to be displayed |
| 29 | + * @return the user input |
| 30 | + */ |
| 31 | + public static int askForNumericalInput(String message) |
| 32 | + { |
| 33 | + return messageBox.askForNumericalInput(message); |
| 34 | + } |
| 35 | + /** |
| 36 | + * Prints a request for a text input to the window. <br> |
| 37 | + * <b>Example:</b> |
| 38 | + * {@code String name = MessageBox.askForTextInput("What is your nickname?");} |
| 39 | + * |
| 40 | + * @param message |
| 41 | + * the text to be displayed |
| 42 | + * @return the user input |
| 43 | + */ |
| 44 | + public static String askForTextInput(String message) |
| 45 | + { |
| 46 | + return messageBox.askForTextInput(message); |
| 47 | + } |
| 48 | + /** |
| 49 | + * Prints the message to the window. <br> |
| 50 | + * <b>Example:</b> {@code MessageBox.showMessage("Girl programmers rule!");} |
| 51 | + * |
| 52 | + * @param message |
| 53 | + * the text to be displayed |
| 54 | + */ |
| 55 | + public static void showMessage(String message) |
| 56 | + { |
| 57 | + messageBox.showMessage(message); |
| 58 | + } |
| 59 | + public static void mock(MessageBoxInstance messageBoxMock) |
| 60 | + { |
| 61 | + messageBox = messageBoxMock; |
| 62 | + } |
| 63 | + public static class MessageBoxInstance |
| 64 | + { |
| 65 | + public int askForNumericalInput(String message) |
| 66 | + { |
| 67 | + String input = askForTextInput(message); |
| 68 | + return NumberUtils.load(input, 0); |
| 69 | + } |
| 70 | + public String askForTextInput(String message) |
| 71 | + { |
| 72 | + return JOptionPane.showInputDialog(message); |
| 73 | + } |
| 74 | + public void showMessage(String message) |
| 75 | + { |
| 76 | + JOptionPane.showMessageDialog(null, message); |
| 77 | + } |
| 78 | + } |
77 | 79 | } |
0 commit comments