[英]Adding a TextField to JOptionPane
我正在研究一个显示“ Hello”并使用JOptionPane接受用户输入的简单程序。 我想阅读用户输入并将其与显示的单词进行比较。 例如,程序将显示“ Hello”,并且用户将不得不在文本框中输入单词。 如果他们键入“ Hello”,则将打印“ Correct”。 如果他们没有键入Hello,则将显示“ Incorrect”。 为了读取用户输入并比较两个字符串,我需要做什么?
public static void main(String[] args){
String resp = "Hello";
JOptionPane.showInputDialog(null, resp);
String input = ; //what should go here
if (resp.compareTo(input) == 0) {
JOptionPane.showMessageDialog(null, "Correct!");
} else
JOptionPane.showMessageDialog(null, "Incorrect");
}
}
}
public static void main(String[] args)
{
String resp = "Hello";
String input = JOptionPane.showInputDialog(null, resp);
if (resp.compareTo(input) == 0)
JOptionPane.showMessageDialog(null, "Correct!");
else
JOptionPane.showMessageDialog(null, "Incorrect");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.