[英]Java search in text file with joptionpane?
Im really new to Java. 我对Java真的很陌生。 So im quite lost here, im working on a project where i should search in a text file for a corresponding word, line by line.
所以我在这里很失落,我正在一个项目上工作,我应该在文本文件中逐行搜索相应的单词。 I got a little help from someone, but there´s some errors to the GUI in the joptionpane.
我从某人那里得到了一些帮助,但是joptionpane中的GUI出现了一些错误。
This is what i have until now. 这就是我到目前为止所拥有的。 My GUI:
我的GUI:
private void jMenuItemLookupActionPerformed(java.awt.event.ActionEvent evt) {
JOptionPane.showOptionDialog(null, "Title", "Message",
JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE,
null, options.toArray(new String[] {}), options.get(0));
}
And my code for the search. 还有我的搜索代码。
public String lookup(String question){
List<String> options = new ArrayList<>();
for (Object value : data.values()) {
if (value.toString().startsWith(question)) {
options.add((String) value);
}
}
Move your List<String> options = new ArrayList<>();
移动您的
List<String> options = new ArrayList<>();
outside the lookup
method and make it a class variable. 在
lookup
方法之外并使其成为类变量。 Your compiler cannot find options object. 您的编译器找不到选项对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.