I've tried using things like revalidate()
and repaint()
, but it always fails to compile; I know i'm making some kind of mistake somewhere, but I'm just not sure how or where. I've taken all the buttons out of this one and decided to start from scratch with it; I know there are lots of other forums with similar things, but I was finding it very difficult to transfer across what they were using because it is pretty much bespoke from what I can gather. Any help would be much appreciated.
//import java libraries
import java.awt.*;
import javax.swing.*;
public class Emotion extends JFrame
{
private JLabel label;
private JLabel phrasem;
public Emotion()
{
setLayout( new FlowLayout());
//Wordlists
String[] wordlist =
{
"Anger","Misery","Sadness","Happiness","Joy","Fear","Anticipation","Surprise","Shame","Envy","Indignation","Courage","Pride","Love","Confusion","Hope","Respect","Caution","Pain","Rage Melon"
};
//number of words the list
int length = wordlist.length;
/random number
int rand = (int) (Math.random() * length);
//building phrase
String phrase = wordlist[rand];
// printing phrase
phrasem = new JLabel("Today your emotion is:");
add (phrasem);
label = new JLabel(" " + phrase);
add (label);
}
public static void main(String[] args)
{
Emotion gui = new Emotion();
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gui.setSize(400, 100);
gui.setVisible(true);
gui.setTitle("My App (Alex Gadd)");
}
}