I have a quotes program. The author name is the key and the quote is the value in the hashmap. I know how to iterate through and print out all the values to the command line, but what I need to do is with each click of the next quote button, the next value(quote) in the hashmap is displayed in the text area. So far what I have will only get the last quote since it returns after the while loop, so if anyone has an idea that would be great.
here is the get method in quotes collection class
public String get() {
Set entries = quoteTable.entrySet();
Iterator it = entries.iterator();
String fullQuote = "";
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
fullQuote = "\"" + entry.getValue() + "\" - " + entry.getKey();
}
return fullQuote;
}
and here is the method to display it to the text area
public void nextButton_actionPerformed(ActionEvent e) {
QuotesCollection qc = new QuotesCollection();
String quoteDisplay = qc.get();
messageTextArea.setText("");
messageTextArea.append(quoteDisplay);
}