simpleinput.java

来自「Java code Bankline to allocated the sour」· Java 代码 · 共 48 行

JAVA
48
字号
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 + =
减小字号Ctrl + -
显示快捷键?