一串挣扎这里是我的代码我与创建一个随机单词,而不是单词
我得到的话,而不是只是一个字符串,我想我已经完全做到了。如果你能给我一些很棒的指针,我将所有的代码包含进去的唯一原因是我可能看过的东西,我认为它与构建这个短语有关,但我不确定
//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)");
}
}
谢谢,这真是帮了:) – user2648747