I created a enumeration with a few words. I want a word at random to be selected on displayed on the gui, however, I am unsure of how to have the random word actually display. If anymore info is needed, feel free to let me know, thank you!
Here is the enum:
public enum Words {
RIFLE,RAILROAD,FARM,SLOPE,LEPERACHAUN,SONG,CREATOR,TENT,FORM,FOOD,DINNER,TICKET,NOVEL,SPARK,
KITTEN,GUST,SMOKE,HORSE,LOSS,BRAKE,JAZZ,BASEBALL,SIZZLE,LEOPARD,SPARROW,EGG,QUARTER,MULTIPLE,DUPLEX,VOICE,
GNU,UNDERWEAR,SAND,BED,CANNON,NOTEBOOK,CAUSE,DIRT,PYTHON,SWING,WORD,RAY,SNOW,TRUCK,SILVER,NERVE,DEATH,
SEASHORE,WATER,COBWEB;
public String toString() {
String name = name();
return name.substring(0, 1) + name.substring(1);
}
}
Here is the view, where I want a word to display:
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import acm.graphics.GLabel;
import acm.program.Program;
public class HangmanView implements MouseListener, ActionListener {
private static final int DEFAULT_SIZE = 600;
private static final Font FONT = new Font("Helvetica", Font.BOLD, 20);
private JLabel statusMsg;
private Words words;
HangmanGraphics Content = new HangmanGraphics(DEFAULT_SIZE/2,DEFAULT_SIZE/2);
Hangman game; // the controller
HangmanModel model; // the model
public HangmanView(Hangman game) {
final GLabel label = new GLabel(words.toString());
label.setFont(FONT);
game.add(label, DEFAULT_SIZE/4, DEFAULT_SIZE/4);
}
}