📄 simpleinput.java
字号:
package miscLib;import javax.swing.JOptionPane;/** * Title: SimpleInput.java * Description: Provides class methods for input data using JOptionPane.showInputDialog */public abstract class SimpleInput { public static int getInteger(String prompt) { do { try { return Integer.parseInt(JOptionPane.showInputDialog(null, prompt)); } catch (NumberFormatException nfe) { JOptionPane.showMessageDialog(null, "Invalid integer!"); } } while (true); } public static float getFloat(String prompt) { do { try { return Float.parseFloat(JOptionPane.showInputDialog(null, prompt)); } catch (NumberFormatException nfe) { JOptionPane.showMessageDialog(null, "Invalid number!"); } } while (true); } public static String getString(String prompt) { return JOptionPane.showInputDialog(null, prompt); } public static char getChar(String prompt) { String s; do { s = JOptionPane.showInputDialog(null, prompt); if (s.length() == 1) return s.charAt(0); } while (true); }} // class SimpleInput
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -