这是我的代码
我得到一串单词而不是一个单词,我认为我做得很好。如果你能给我一些很棒的建议,我包含所有代码的唯一原因是我可能看多了一些东西,我认为这与短语的构建有关,但我不确定
//import java libraries
import java.awt.*;
import javax.swing.*;
public class Emotion extends JFrame
{
//set what you can use
private JLabel label;
private JLabel phrasem;
public Emotion()
{
setLayout( new FlowLayout());
//Wordlists
String[] wordlistone =
{
"anger","misery"+"sadness"+"happiness"+"joy"+"fear"+"anticipation"+"surprise"+"shame"+"envy"+"indignation"+"courage"+ "pride"+"love"+"confusion"+"hope"+"respect"+"caution"+"pain"
};
//number of words in each list
int onelength = wordlistone.length;
//random number
int rand1 = (int) (Math.random() * onelength);
//building phrase
String phrase = wordlistone[rand1];
// printing phrase
phrasem = new JLabel("PhraseOMatic says:");
add (phrasem);
label = new JLabel("Today you emotion is: " + 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)");
}
}