为什么 Java 输入对话框中有数字 3?
Why is there number 3 at Java input dialog?
String response = JOptionPane.showInputDialog(null, "Question", JOptionPane.QUESTION_MESSAGE);
这总是给我一个带有文本输入字段的输入对话框,该文本输入字段始终显示输入字段中写的数字 3。这是为什么?
您应该检查您的代码,因为 JOptionPane class 准确地显示了它收到的内容,所以周围可能有错位的“3”。
你为什么不分享更多你的代码或者尝试使用你喜欢的 IDE(Netbeans、Eclipse...)调试你的代码
您正在呼叫 showInputDialog(Component parentComponent, Object message, Object initialSelectionValue)
,并且您正在传递 QUESTION_MESSAGE
(即数字 3)作为 initialSelectionValue
。
您可以改为调用 showInputDialog(Component parentComponent, Object message, String title, int messageType)
,它有一个 messageType
参数,该参数接受 QUESTION_MESSAGE
.
这意味着将您的代码更改为:
showInputDialog(null, "Question", "Title", JOptionPane.QUESTION_MESSAGE)
并尝试查看 API 以确定您实际尝试调用的方法。
String response = JOptionPane.showInputDialog(null, "Question", JOptionPane.QUESTION_MESSAGE);
这总是给我一个带有文本输入字段的输入对话框,该文本输入字段始终显示输入字段中写的数字 3。这是为什么?
您应该检查您的代码,因为 JOptionPane class 准确地显示了它收到的内容,所以周围可能有错位的“3”。
你为什么不分享更多你的代码或者尝试使用你喜欢的 IDE(Netbeans、Eclipse...)调试你的代码
您正在呼叫 showInputDialog(Component parentComponent, Object message, Object initialSelectionValue)
,并且您正在传递 QUESTION_MESSAGE
(即数字 3)作为 initialSelectionValue
。
您可以改为调用 showInputDialog(Component parentComponent, Object message, String title, int messageType)
,它有一个 messageType
参数,该参数接受 QUESTION_MESSAGE
.
这意味着将您的代码更改为:
showInputDialog(null, "Question", "Title", JOptionPane.QUESTION_MESSAGE)
并尝试查看 API 以确定您实际尝试调用的方法。