我正在构建一个需要用户请求的应用程序。应用程序的第一个版本我自己创建了一个输入窗口,但我发现更好的改变showInputDialog,因为它是JOptionFrame的预模制工具。现在我遇到了事件触发器的问题;看看下面的代码:
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调用事件?可能吗?谁会成为听众?在此先感谢
答案 0 :(得分:0)
我找到了自己的答案 - 确实要将事件搜索类的代码继续执行并将触发器拉到这样的一个动作上,而不是最好:
public SearchScreen(){
userQuery = (String) JOptionPane.showInputDialog("Type Keywords in english to be requested below:");
try {
//Your Action with the String
} catch (IOException e1) {
e1.printStackTrace(); //print failure
JOptionPane.showMessageDialog(null, "FAILURE");
}
}