0

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)");

    }

 }
rootmeanclaire
  • 808
  • 3
  • 13
  • 37
  • 1
    What is the error that you get? I did not see any compile errors in the code you posted except for a missing '/' for the comment '/random number'. You would get better help, if you specify what exactly you are trying to do, and where you need help. – sreejit Aug 05 '13 at 06:25
  • The question is unclear, though, if you want that at the click of this `Refresh JButton`, all fields must be cleared, then you can use a function like as described in the last part of this [example](http://stackoverflow.com/a/13378672/1057230). Hopefully this might help a bit :-) – nIcE cOw Aug 05 '13 at 13:44
  • @sreejit i dont get any errors per say as it all compiles absolutely fine, as for the missing '/' i just copied and pasted wrong, when i do add the button though it appears with the text i wanted but when i actually click the button nothing happens, ive tried several different functions, but none of them seem to have any effect, i suspect that the issue lies with how i assigned the function to the button – user2648747 Aug 05 '13 at 22:55

0 Answers0