[英]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.