我構建了一個需要用戶請求的應用程序。應用程序的第一個版本我自己創建了一個輸入窗口,但是我發現showInputDialog更好,因爲它是來自JOptionFrame的預成型工具。現在我遇到了事件觸發器的問題;看看下面的代碼:通過showInputDialog調用事件
SearchScreen:
public class SearchScreen extends EventSearch{
...
public SearchScreen(){
userQuery = (String) JOptionPane.showInputDialog("Type Keywords in english to be requested below:");
}
...
}
EventSearch:
public class EventSearch extends TabBuilder{
public EventSearch() {
}
public void actionPerformed(ActionEvent Ev) {
try {
System.out.println("worked");
} catch (IOException e1) {
e1.printStackTrace(); //print failure
JOptionPane.showMessageDialog(null, "FAIL");
}
};
}
TabBuilder:
public class TabBuilder implements ActionListener {
.....
}
我接着問,我怎麼通過調用一個事件showInputDialog?可能嗎?誰會成爲聽衆?由於提前
請爲什麼ISN」有沒有任何父 - >'JOptionPane.showInputDialog(null,...',爲更好的幫助儘早發佈[SSCCE](http://sscce.org/),短小,可運行,可編譯 – mKorbel
@mKorbel我的錯誤,我忘記刪除我在測試版本代碼 –
上使用的組件,我不知道你爲什麼要在這裏添加事件處理,但對於這種情況,我認爲這是沒有用的.. ** userQuery **從inputDialog你可以檢查var是null還是空的。然後繼續o ñ用一些方法..我建議學習JOptionPane類進一步添加自定義它 – Dreamer