3

I am working on a very simple text adventure game in Java and I am just wondering how to get it into a window so it will look more like an actual game. Like could I have someone click on an icon and it pop up with this simple game? Thank you for your help and I am sorry if I waste your time!

//bored programming
import java.util.*;
public class test {
    public static void main(String[] args){
    Scanner input = new Scanner (System.in);
    String x = "hey";
    System.out.println("Welcome to adventure game!");
    System.out.println();
    System.out.println("Which way do you want to go?:  ");
    x = input.nextLine();
    if (x.equals ("west")){
        System.out.println("You walk towards the forest.");
        west();
    }
    else if (x.equals("east"))
        System.out.println("You go East!");
    else if (x.equals("south"))
        System.out.println("You go South!");
    else if (x.equals("north"))
        System.out.println("You go North!");
    else
        System.out.println("You cannot go that way!!");
    }


    public static void west(){
    Scanner input = new Scanner (System.in);
    System.out.println("Which way shall you go?");
    String x = input.nextLine();

    }
}
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Josh
  • 163
  • 2
  • 7
  • 23
  • 3
    I don't think a `(J)Applet` is what would be best for the game, instead look to putting the game into a `JFrame` (the components shown in the screenshot [here](http://stackoverflow.com/questions/6182110/file-browser-gui) are inside a `JFrame`). Also note that `Scanner` is well suited to getting data from an `InputStream`, but does not mesh well with GUIs like applets *or* frames. It might be necessary to rethink the approach. Given you don't already have thousands of lines of code, that should not be a great problem. ;) – Andrew Thompson Aug 21 '11 at 02:18

2 Answers2

3

JTextArea may be a good starting point. Examples may be found in the tutorial and here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
1

Just Migrate your code to NetBeans IDE.Create a Window and may be a text box and whatever you want and finally pack it to an executable jar.

techno
  • 6,100
  • 16
  • 86
  • 192
  • The [Java Console](http://download.oracle.com/javase/1,5.0/docs/guide/deployment/deployment-guide/console.html) does not redirect `System.in`, but the game _could_ be played on the user's command line. – trashgod Aug 21 '11 at 09:27