私はスキャナーの経験があまりありませんが、txtファイルから各単語を読み取り、それぞれに対して1つをintに追加するメソッドを作成しましたが、intは増え続けています。最後の単語を読んだり、最後の単語を追加したりしたら止めてほしい。
public void drawnames(Graphics g) throws FileNotFoundException{
int str = 0;
String[] string = new String[800*600];
int xpos = 100;
int ypos = 100;
@SuppressWarnings("resource")
Scanner s = new Scanner(new BufferedReader(new FileReader("Particles/Names.txt")));
while(s.hasNext()){
string[str] = s.next();
g.drawString(string[str] + str, xpos, ypos);
str = str + 1;
ypos = ypos + 100;
}
}