Created
February 17, 2014 02:38
-
-
Save ucarion/9043767 to your computer and use it in GitHub Desktop.
Custom JOptionPane class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package javax.swing; | |
import java.util.Scanner; | |
import java.awt.Component; | |
/** | |
* This is a fake JOptionPane class. It overrides the two most commonly-used | |
* JOptionPane-based functions for IO (#showInputDialog and #showMessageDialog) | |
* and has them simply use System.in and System.out. | |
* | |
* @author Ulysse Carion | |
*/ | |
public class JOptionPane { | |
private static Scanner scanner; | |
static { | |
scanner = new Scanner(System.in); | |
} | |
public static String showInputDialog(Object message) { | |
if (!scanner.hasNextLine()) { | |
return null; | |
} | |
String next = scanner.nextLine(); | |
if (isNullCode(next)) { | |
return null; | |
} else { | |
return next; | |
} | |
} | |
private static boolean isNullCode(String input) { | |
return input.equals("\\0"); | |
} | |
public static void showMessageDialog(Component parentComponent, Object message) { | |
System.out.println(message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment