我正在构建一个需要用户请求的应用程序。该应用程序的第一个版本我自己制作了一个输入窗口,但我发现对 showInputDialog 进行了更好的更改,因为它是 JOptionFrame 的预成型工具。现在我遇到了事件触发器的问题;查看下面的代码:
搜索屏幕:
public class SearchScreen extends EventSearch{
...
public SearchScreen(){
userQuery = (String) JOptionPane.showInputDialog("Type Keywords in english to be requested below:");
}
...
}
事件搜索:
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");
}
};
}
选项卡生成器:
public class TabBuilder implements ActionListener {
.....
}
然后我问,我应该如何通过 showInputDialog 调用事件?是否可以?谁来当听众?提前致谢