import java.util.Scanner;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.WindowConstants;
class DD {
public static void main(String[] args){
JFrame myFrame = new JFrame("#########");
myFrame.setSize(640,480);
myFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
myFrame.setVisible(true);
JTextArea textArea = new JTextArea();
myFrame.add(textArea);
new JTextArea();
textArea.setEditable(false);
//System objects
Scanner in = new Scanner(System.in);
boolean running = true;
textArea.append("\t\n########################################");
textArea.append("\t\n>#############");
textArea.append("\t\n>Th#############11!");
textArea.append("\t\n>Typ#############enture!");
textArea.append("\t\n########################################");
String input = in.nextLine();
if(input.equals("start")){
{ ///beginning of story.
if(running)
textArea.append("\t\nYo#############.");
textArea.append("\t\n#############");
textArea.append("\t\n1.#############t.");
textArea.append("\t\n2.G#############t.");
String input1 = in.nextLine();
if(input1.equals("1")){
textArea.append("\n>Y#############");
textArea.append("\n>#############");
textArea.append("\n>A#############");
textArea.append("\n>1.#############");
textArea.append("\n>2.#############");
if(input.equals("1")){
textArea.append("\n>#############");
textArea.append("\n>#############");
textArea.append("\n>Ga#############d.");
}
if(input.equals("2")){
textArea.append("\n>#############");
textArea.append("\n>#############");
textArea.append("\n>Y#############ars");
textArea.append("\n>Y#############");
}
}
else if(input1.equals("2")){
textArea.append("\n>Y#############.");
textArea.append("\n>Y#############.");
}
}
}
}
}
這是我的文本冒險遊戲,我被困在如何獲得用戶輸入。我已閱讀關於'動作監聽器'我不知道如何使用它,但我真的希望輸入像控制檯或終端/ cmd程序一樣輸入。用戶只需輸入1,2或3來執行一個動作。如何在文本冒險遊戲中獲取用戶輸入(Java/Applet)
可能重複http://stackoverflow.com/questions/5287538/how-to-get-basic-user-input-for-java – Deh
@Deh我不這麼認爲,我認爲(或者我希望)OP正嘗試使用GUI來獲取用戶輸入,但它們只是不明白事件驅動環境的基本概念 – MadProgrammer
@MadProgrammer哦,是的,這是正確的被標題欺騙,那麼這一個可能是http://stackoverflow.com/questions/16390503/java-swing-getting - 從jtextfield輸入 – Deh