Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Please help!! simple question

 
asheet anand
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everyone,
could you please tell me the way to sort the elements in an awt.list.i'm making a chat program and adding and removing the user as they entered and leave the chat room.Please tell me how i can sort these names.
i'll be highly obliged.
asheet anand
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've never used an awt.List before, but I can make a suggestion based on the API.

There isn't a constructor for the list that allows you to give it a pre-sorted list, but instead you'd have to use .add(String item, int index)

Doing it this way, you'd need to ensure that every time you go to insert a name, that you are inserting it in the right place. Sort of like linked lists. You could use the getItems() which returns an array of Strings. Then you can compare each String in that array with the String you want to insert. As soon as you find that the current array String (at [index]) is alphabetically 'after' the one you want to insert.. then use [index - 1] as the parameter to the add method like: .add(String nameToInsert, int index -1)

Something I just thought of... the API doesn't specify if the item that is currently at that index gets removed, or if everything bumps down one (like in a Vector). If it doesn't get bumped down, then you will need to implement this bump-down behaviour yourself.
 
jagdish karki
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TO ,
sort the list you get the user names of the chatters from the database presorted.And your work is to remove all elements from the list and add the new members as fresh items.
Jaggi.
------------------
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!