Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. ArrayList<Record> highScoreList;
  2. highScoreList = new ArrayList<>();
  3. highScoreReading(highScoreList);
  4. window.setOnCloseRequest(e -> {
  5. e.consume();
  6. highScoreSaving(highScoreList);
  7. window.close();
  8. });
  9.  
  10. private void highScoreReading(ArrayList<Record> highScoreList){
  11. try{
  12. ObjectInputStream ois=new ObjectInputStream(new FileInputStream("highscore"));
  13. while(highScoreList.add((Record)ois.readObject())){/*semmi*/ }
  14. } catch (IOException io){
  15. } catch (ClassNotFoundException cnfe){
  16. }
  17. }
  18.  
  19. private static void highScoreSaving(ArrayList<Record> highScoreList){
  20. //először rendezünk
  21. Collections.sort(highScoreList, new ScoreComparator());
  22. Collections.reverse(highScoreList);
  23. try {
  24. ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("highscore"));
  25. Iterator<Record> it = highScoreList.iterator();
  26. while(it.hasNext()){
  27. oos.writeObject(it.next());
  28. }
  29. } catch (IOException io){
  30. //vmi amivel lekezelem
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement