我试图创建一个刷新按钮,并继续失败

时间:2013-08-05 01:10:15

标签: swing random jframe refresh

我尝试过使用像revalidate()repaint()之类的东西,但总是无法编译;我知道我在某处犯了某种错误,但我不确定如何或在哪里。我从这个按钮中取出了所有按钮,并决定从头开始使用它;我知道有很多其他论坛都有类似的东西,但我发现很难转移他们正在使用的东西,因为它几乎是我可以收集的定制。任何帮助将不胜感激。

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

    }

 }

0 个答案:

没有答案