2016-09-01 2 views
1

FileとString配列をリンクする際に少し問題があります.File配列の各要素をString配列の対応する数値に一致させたい(単語[1]と答えると[1]と答える)私はそれについて考えを持っていません....助けてくれてありがとう!ファイル配列と文字列配列のコラボレーション

private static File[] word = 

    { new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\audio.mp3"), 
     new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\baby.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\board.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\bomb.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\gym.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\football.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\school.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\keyboard.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\computer.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\name.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\lady.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\church.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\sport.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\beauty.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\radio.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\prince.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\hearing.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\worship.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\song.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\flower.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\water.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\nature.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\goal.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\manifest.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\election.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\number.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\sentence.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\movie.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\sound.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\teacher.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\speed.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\time.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\debate.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\video.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\music.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\phone.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\mountain.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\drink.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\market.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\broom.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\help.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\picture.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\princess.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\cake.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\river.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\dance.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\rely.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\level.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\wealth.mp3"), 
    new File ("C:\\Users\\HP\\Downloads\\Word Pronunciation\\surname.mp3") }; 

    private String []answer = {"audio", "baby", "board", "bomb", "gym", "football", "school", "keyboard", "computer", "name" , 
      "lady", "church", "sport", "beauty", "radio", "prince", "hearing", "worship", "song", "flower", "water", "nature", "goal" , 
      "manifest", "election", "number", "sentence", "movie", "sound", "teacher", "speed", "time", "debate", "video", "music", 
      "phone", "drink", "market", "broom", "help", "picture", "princess", "cake", "river", "dance", "rely", "level", "wealth", "surname"}; 

JButton click = new JButton(); 

public class Beginner(){ 

click = new JButton("1"); 

click.addActionListener(new ActionListener(){ 
public void actionPerformed (ActionEvent x){ 

    } 
}); 
} 
} 
+0

あなたは 'word [1]'と 'answer [1]'をマッチさせたいと思っています.... * ehhhh * ....まあ、あなたはやっただけです。彼らは*同じ*インデックス値を持っています。それが彼らのマッチング方法です。あなたの問題は何でしたか? – Andreas

答えて

1

Mapを使用する方がよいでしょう。

Map<String, File> mapping = new HashMap<>(); 
mapping.put("audio", new File("C:\\Users\\HP\\Downloads\\Word Pronunciation\\audio.mp3"); 
// etc... 

してから使用して値を取得:

File file = mapping.get("audio"); 
1

のJava 8の方法は

Map<String, File> mapping = IntStream.range(0, word.length) 
.collect(Collectors.toMap(i -> answer[i], i -> word[i])); 

があなたの配列をリンクすることです。