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

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -