วันจันทร์ที่ 5 กันยายน พ.ศ. 2554

Hight Score from File on Dialog

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class Read {
 Read() throws IOException{
  FileReader read = new FileReader("score.txt");
  BufferedReader file = new BufferedReader(read);
  String readFile = file.readLine();
  String real = "";
  while (readFile!=null) {
   real = real+readFile;
   readFile = file.readLine();
  
  
  
  }
  String hightscore[] = real.split(",");
  String name[] = new String[hightscore.length];
  String score[] = new String[hightscore.length];
  String scoreCheck[] = new String[hightscore.length];
  for(int i =0;i<hightscore.length;i++){
   String nameSp[] = hightscore[i].split(" ");
    name[i] = nameSp[0];
    score[i] = nameSp[1];
   
  
  }
  scoreCheck = score;
  Arrays.sort(score);
  String showHighScore[] =new String[score.length];
  String showOnDilog ="";
  for(int i=0; i<score.length;i++){
  
   for(int j=0;j<scoreCheck.length;j++){
   
    if(score[i].equals(scoreCheck[j])){
     showHighScore[i] = name[j]+"                   "+score[i];
    
    
    }
   }
  }
 
  for(int i=showHighScore.length-1;i>=0;i--){
   showOnDilog = showOnDilog+showHighScore[i]+"\n";
  }
 
   JOptionPane.showMessageDialog(null,"              Hight Score\n"+showOnDilog ,"High Score",JOptionPane.INFORMATION_MESSAGE );
 }
 public static void main(String[] args) throws IOException {
  new Read();
 }
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น