JCombo Box and Hashmap confusion
Hi, I am trying to create JCombo Box for sorting images by name, title, most recent etc.
First I created Hashmap below is the code which does the sorting orders.
My question is how do I connect this sorting with JComboBox drop down menu. Please can you make this work for me by writing the code.
Code:
import java.util.*; // For collections.
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
// *************************************************************************
/** An application for handling a simple photo database.
*
// *************************************************************************
public class RunPhotoApp2 extends JFrame implements ActionListener
{
/** Creates a simple photo database and displays simple query results.
* @param args Command line arguments (ignored).
*/
public static void main(String[] args)
{
// Create the two tables.
Map<Long,Photo> photos = new HashMap<Long,Photo>();
photos.put(3609624150L,new Photo("Female Rabid Wolf Spider","7539598@N04","08062009"));
photos.put(3596720576L,new Photo("Head of Long Legged Fly", "7539598@N04","04062009"));
photos.put(4336541668L,new Photo("Bronco", "55186440@N00","06022010"));
photos.put(4162213878L,new Photo("P1050942v01-frost-rose", "14884524@N08","05122009"));
Map<String,Contributor> contributors = new HashMap<String,Contributor>();
contributors.put("7539598@N04", new Contributor("Thomas Shahan",230));
contributors.put("55186440@N00", new Contributor("Brian DeMeester",610));
contributors.put("14884524@N08", new Contributor("Kilarin",104));
// Create a sorted list of photos.
TreeSet<Photo> sortedPhotos = new TreeSet<Photo>(photos.values());
// Do a query and display the results.
for (Photo photo : sortedPhotos)
{
Contributor contributor = contributors.get(photo.getContributorID());
System.out.println(photo.getTitle()+" by "+contributor.getName());
}
}
}
Re: JCombo Box and Hashmap confusion
Quote:
Originally Posted by
gsb1bee
Please can you make this work for me by writing the code.
...
Please have a seat while we whip this up for you; it shouldn't take too long. Also, feel free to help yourself to some coffee and doughnuts while you wait.