/Users/lyon/j4p/src/utils/IO.java
|
1 package utils;
2
3
4 public class IO {
5 public static void show(Object s) {
6 javax.swing.JOptionPane.showMessageDialog(null, s);
7 }
8
9 public static String getString(Object o) {
10 return javax.swing.JOptionPane.showInputDialog(o);
11 }
12
13 public static int getInt(Object o) {
14 String s = getString(o);
15 try {
16 return Integer.parseInt(s);
17 } catch (NumberFormatException e) {
18 return getInt(s + " is not an int!" + o);
19 }
20 }
21
22 public static double getDouble(Object o) {
23 String s = getString(o);
24 try {
25 Double d = Double.valueOf(s);
26 return d.doubleValue();
27 } catch (NumberFormatException e) {
28 return getDouble(s + " is not a double!" + o);
29 }
30 }
31
32 public static void main(String args[]) {
33 show(
34 "Hello " +
35 getString("Please Enter your name:"));
36 show("age=" +
37 getInt("Enter your age:"));
38 }
39 }