I'm trying to set the text of a text field to a string based on the value selected in a JList
.
JList
=list
LinkedList<WordPair>
=wordpair_list
WordPair
containswordA
andwordB
If anyone can explain to me why this doesn't work I would be forever in your debt. there is obviously a lot more code in this program, but stackoverflow
seems to think my text to code ratio is disproportionate. if you personally want the rest of the code I'd be glad to send it to you if you are up for the challenge.
public void showTranslation(){
int i = wordpair_list.indexOf(list.getSelectedValue());
textField.setText(wordpair_list.get(i).getWordB());
}
public Dictionary(Object o){
if (o instanceof String){
String filename = (String) o;
File file = new File(filename);
Scanner sc = null;
try {
sc = new Scanner(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
while (sc.hasNextLine()){
words.add(new WordPair(sc.nextLine()));
}
}
}
public WordPair(String arg0) {
arg0.trim();
int equalsIndex = arg0.indexOf("=");
this.wordA = arg0.substring(0, equalsIndex-1);
this.wordB = arg0.substring(equalsIndex+1);
}