String noun1 = jTextField1.getText();
String noun2 = jTextField1.getText();
String noun3 = jTextField1.getText();
String verb1 = jTextField1.getText();
String verb2 = jTextField1.getText();
String verb3 = jTextField1.getText();
String adj1 = jTextField1.getText();
String adj2 = jTextField1.getText();
String adj3 = jTextField1.getText();
String story = "This is the story about a " + noun1;
jTextArea1.setText(story);
我正在使用 JFrame 创建一个 Madlibs,需要找出如何在新行上继续字符串(我忘记了),例如 Story。我需要它继续,以便我可以添加其他句子。
最佳答案
使用行分隔符
String story = "This is the story about a" + System.lineSeparator() + noun1;
或者使用\n
作为新行
String story = "This is the story about a\n" + noun1;
当您想要打印出来时,您还可以使用更多 System.out.println(...)
命令。
System.out.println("This is the story about a"); // Print the string inside and add a linebreak afterwards
System.out.println(noun1); // Print the value of noun1 variable
所有这些都会给你以下结果:
This is the story about a
"your story name"
更多信息在这里:Java String new line
关于java - 换行继续字符串的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35276089/