PHP Code:
import javax.swing.JOptionPane;
public class DoAgain {
public static boolean ask() {
String again;
do {
again = JOptionPane.showInputDialog("Again? y or n? ");
System.out.println("Again? y or n? " + again);
} while (again.equals("y") && !again.equals("n"));
return again.equals("y");
}
}
PHP Code:
import javax.swing.*;
public class IO {
public static int getInt(String message) {
int num = 0;
try {
num = Integer.parseInt(JOptionPane.showInputDialog(message).trim());
System.out.println(message + ": " + num);
} catch (NumberFormatException e) { // test for bad input
System.err.println(e.toString()); // error message
System.exit(0); // stop program
}
return num;
}
public static double getDouble(String message) {
double num = 0;
try {
num = Double.parseDouble(JOptionPane.showInputDialog(message).trim());
System.out.println(message + ": " + num);
} catch (NumberFormatException e) { // test for bad input
System.err.println(e.toString()); // error message
System.exit(0); // stop program
}
return num;
}
public static String getString(String message) {
String s = JOptionPane.showInputDialog(message);
System.out.println(message + ": " + s);
return s;
}
public static char getChar(String message) {
String s = JOptionPane.showInputDialog(message);
if (s.length() == 0) {
System.out.println(message + ": ");
return '\0';// null char
} else {
System.out.println(message + ": " + s.charAt(0));
return s.charAt(0); // first char
}
}
public static void println(String message) {
System.out.println(message);
JOptionPane.showMessageDialog(null, message);
}
}
My 2 versions.
Generic knows way more Java than you do, just saying.