Confused about Comparator with Collections.sort (java)

I'll post the full program in a comment.

The main thing is I'm confused on how to use comparator (with the compare method) with Collections.sort(list, comparator<t> t) <-- Generic idea. More detail in program.

But what I need to do is I have a GUI that displays a list of Ellipse. It displays the Major Axis, Minor Axis, Perimeter, and Area. I need to be able to sort this list by the four different variables. I believe I need to use either comparator or comparable. I have four buttons set up and depending on which button I press, the program must sort the list by that variable. Any help would be greatly appreciated!

Posted Dec 2, 2011, 1:12 AM UTC

27
Loading comments…