我正在构建一个需要用户请求的应用程序。该应用程序的第一个版本是我自己创建的一个输入窗口,但是我发现对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");
}
};
}
TabBuilder:
public class TabBuilder implements ActionListener {
.....
}
然后我问,我该如何通过showInputDialog调用事件?是否有可能?谁将成为倾听者?提前致谢
我找到了自己的答案-实际上,它可以继续执行Event Search类的代码并将触发器触发到这样的一个动作,相反,这样做更好:
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");
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句