Change Highscore list from ASC to DSC. Urgent

Hi guys. I need help with changing the sort type of this code.

I write the output in an jTextArea Field with Descending order. it looks like

Viktor = 40

Thomas=65

Emil=30

Alfred=120

so you see that the names are sorted. i want the points (score) to be sorted.

The data is saved into an properties file which looks so

#Highscore-Properties

#Mon Jan 22 22:12:48 CET 2007

Viktor=80

Dora=90

Hans=200

Bertie=1000

Sepp=400

public HighScore()

throws Exception

{

myScore.load(new FileInputStream(System.getProperty("user.dir") + File.separator +"score.properties"));

}

/* returns Sortedmap mit key = Playername & Value-Score */

public SortedMap getScoreList()

{

SortedMap score =new TreeMap();

Enumeration keys = myScore.keys();

if (keys !=null)

{

while (keys.hasMoreElements())

{

String tname = keys.nextElement().toString();

score.put(tname, myScore.getProperty(tname));

// HOW TO CHANGE THIS PIECE OF CODE?

}

return score;

}

returnnull;

}

/* If player is in properties list and score is higher than the new

* then it writes the higher score in the file.

*@param nickname = player

*@param score = Highscore

*/

publicvoid setnewScore(String nickname,int score)

throws Exception

{

if (myScore.getProperty(nickname) !=null && Integer.parseInt(myScore.getProperty(nickname).toString()) < score)

{

myScore.setProperty(nickname,""+score);

myScore.store(new FileOutputStream(System.getProperty("user.dir") + File.separator +"score.properties"),"Highscore-Properties");

}

elseif (myScore.getProperty(nickname) ==null)

{

myScore.setProperty(nickname,""+score);

myScore.store(new FileOutputStream(System.getProperty("user.dir") + File.separator +"score.properties"),"Highscore-Properties");

}

}

/*

I wrote the main method in my other visual class when the window is activated

instead of the system.out.println i wrote

jTextArea2.setText("Spieler: " + player + " Score: " + sm.get(player)+"\n"+jTextArea2.getText());

writes all players who are in the score list (alphabetical ordered)

*@param args

*/

publicstaticvoid main(String[] args)

{

try{

HighScore hs =new HighScore();

SortedMap sm = hs.getScoreList();

Iterator ene = sm.keySet().iterator();

while (ene.hasNext())

{

Object player = ene.next();

System.out.println("Player: " + player +" Score: " +sm.get(player));

}

}catch (Exception e)

{

e.printStackTrace();

}

}

}

I am sorry for my bad english.

It would be very nice if someone could tell me what to change in my code.

ty

Message was edited by:

Shadowli

[4973 byte] By [Shadowlia] at [2007-11-26 15:52:32]
# 1
Extract the highscores into an object which can be sorted using Collections.sort - either a Comparable or something for which you can write a Comparator - and populate an ArrayList with these objects. Then sort it.
YAT_Archivista at 2007-7-8 22:12:51 > top of Java-index,Other Topics,Java Game Development...
# 2
ty for your answer. has anyone complete code for this?
Shadowlia at 2007-7-8 22:12:51 > top of Java-index,Other Topics,Java Game Development...
# 3
> ty for your answer. has anyone complete code for this?Why thank him if you're not going to do something with the advice given to you?
prometheuzza at 2007-7-8 22:12:51 > top of Java-index,Other Topics,Java Game Development...
# 4
> > ty for your answer. has anyone complete code for> this?> > Why thank him if you're not going to do something> with the advice given to you?Probably the same reason, he claims it's "his" code... He is lying.
macrules2a at 2007-7-8 22:12:51 > top of Java-index,Other Topics,Java Game Development...
# 5

yes... the set and get scorelist is not from me.

the tipp is good, but i can not code it because i am extreme java newbie.

so it would be very nice if i get the pieces of code i need because i need the highscore list till tomorrow.

in the meantime i tried other way round. set from nickname=score to score=nickname but because of the enumeration it sorts like

50 hans

30 thomas

20 emil

205 name

19 name

1394 emil

0 name

so please help me.

Sha-dowlia at 2007-7-8 22:12:51 > top of Java-index,Other Topics,Java Game Development...