JOptionPane并从输入中获取文本

use*_*187 2 java string swing joptionpane

我创建了一个打开的按钮JOptionPane.它允许用户输入string..>> String str = JOptionPane.showInputDialog 如何获取用户输入到joptionpane的文本并使用它来搜索userobjects?

非常感谢

JB *_*zet 6

返回的String是用户输入的内容,如果用户选择取消,则返回null:

String whatTheUserEntered = JOptionPane.showInputDialog(...);
if (whatTheUserEntered == null) {
    System.out.println("The user canceled");
}
Run Code Online (Sandbox Code Playgroud)