我在taskBckg.java
文件中有以下行:
userInput.askGetInput("There were errors creating the file. " +
"Would you like to continue ahead with diagnostics? " +
"(Type "y" or "yes", or "n" or "no".) " +
"This will only take a minute.");`
这个调用实际上通过了另一种方法,我还不确定,但我想通过这种方法(提出问题并返回答案)以某种方式请求用户响应——这里有什么想法吗?
// ask question, and return a response...
public String askGetInput(String outText) {
// Update textArea with question
writeToTextArea(outText);
// Wait for the user to respond, and press the submit button
return uI.getText();
}
不知道该怎么做。
使用JOptionPane.showInputDialog(Component,Object)
。
例如
String message = JOptionPane.showInputDialog(mainFrame,"Enter some text");
但现在我更仔细地查看您的代码,您似乎需要一个"是/否"的答案,这更适合JOptionPane.showConfirmDialog(Component,Object)
。
int result = JOptionPane.showConfirmDialog(mainFrame, outputMessage);
if (result==JOptionPane.OK_OPTION) {
// ...
这两种方法都有重载的参数,请检查JavaDocs中的其他变体。