private void createword(JPanel p) throws Exception {
ArrayList<String> lines = new ArrayList<String>();
Scanner getWord = new Scanner(new File("hangman"));
while (getWord.hasNextLine()) {
lines.add(getWord.nextLine());
}
Random rand = new Random();
String selectedword = rand.toString();
int selection = rand.nextInt(lines.size());
for(int i = 0; i < lines.get(selection).length(); i++){
word += " _ ";
}
JLabel label = new JLabel(word, SwingConstants.CENTER);
p.add(label);
hangword = selectedword.toString();
}
what i want to know is, how can i make the selected random word in the program be stored in the String hangword like at the bottom of this? do i have it right already?

New Topic/Question
Reply




MultiQuote


|