swing - How to get users input in a text adventure game (Java/Applet) -
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#############."); } } } } }
this text adventure game, i'm stuck on how users input. have read 'action listener' don't know how use it, want input entered in console or terminal/cmd program. user needs enter 1, 2 or 3 preform action.
dump scanner
start with. use jtextfield
. need understand you're operating in event driven environment, means need make use of observer pattern notified when changes
start taking @ creating gui jfc/swing, how use text fields, how write action listeners more details
Comments
Post a Comment