Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Button to retrieve next value in Hashmap

807606Feb 25 2007 — edited Feb 26 2007
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);
    }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 26 2007
Added on Feb 25 2007
16 comments
424 views