   [java] Java Applet Text based game
  Hello im starting to learn java. I know python,basic,c an c++,i wanna start working with java. Im having a problem. When i use the textfield an type straight it doesnt show the next set of text. An i wanna also do is make the text not show all up at once. Mabey like a slow scroll an after the user inputs something it should scroll. I dont know i would like to get the problem im having fixed before i move on to something else. Thanksimport java.applet.Applet;import java.awt.*;import java.util.Scanner;public class Main extends Applet{/** *  */private static final long serialVersionUID = 1L;String text;Scanner user_in = new Scanner(System.in);Label lab1;   TextField t1; public void init()    {    t1 = new TextField(12); add(t1);    }public void paint(Graphics g)    {   super.paintComponents(g);//calls super-class    Color black = new Color(0,0,0);//creates color Black    Color white = new Color(255,255,255);   setBackground(black); // Sets the background    setForeground(white);    g.drawString("Welcome to Immortal Online ",10,50); g.drawString("You see a town ahead."+"\n"+"Type 'Straight' and hit enter to go to town,'right' to go to the field,"+"\n"+" or 'left' to go to the forest.",10,65);   text = t1.getText();   if (text.equalsIgnoreCase("text"))   {    g.drawString("You are now in town", 10, 85);   g.drawString("What do you want to do",10, 95);   }  }} 
  This should get you started.import java.applet.Applet;import java.awt.BorderLayout;import java.awt.event.KeyEvent;import java.awt.event.KeyListener;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.JTextField;public class Test extends Applet {    private JTextArea messageArea;    private JTextField inputField;   public void init() {   setLayout(new BorderLayout(0, 5));   inputField = new JTextField();   add(inputField, BorderLayout.SOUTH);   messageArea = new JTextArea();   JScrollPane messageScroll = new JScrollPane(messageArea);   add(messageScroll, BorderLayout.CENTER); inputField.addKeyListener(new KeyListener() {  @Override  public void keyTyped(KeyEvent arg0) {  }    @Override  public void keyReleased(KeyEvent arg0) {  }    @Override  public void keyPressed(KeyEvent arg0) { if(arg0.getKeyCode() == KeyEvent.VK_ENTER) {messageArea.insert(inputField.getText() + "\n", messageArea.getText().length());inputField.setText("");messageArea.insert("Message processed\n", messageArea.getText().length()); }  }   });    }};  Cool thank you im going to mess around with what you gave me if i run into any problems i will be back. Thanks   ;  ok so i modified your code a little i dont have no errors but the applet just doesnt look right. The background is suppose to be black but it only shows a little line at the bottom.package gm1;import java.applet.Applet;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Graphics;import java.awt.event.KeyEvent;import java.awt.event.KeyListener;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.JTextField;public class Game1 extends Applet {    /** *  */private static final long serialVersionUID = 1L;private JTextArea messageArea;    private JTextField inputField;    String text;   public void init() {   setLayout(new BorderLayout(0, 5));   inputField = new JTextField();   add(inputField, BorderLayout.SOUTH);   messageArea = new JTextArea();   JScrollPane messageScroll = new JScrollPane(messageArea);   add(messageScroll, BorderLayout.CENTER);    }public void paint(Graphics g)   { super.paintComponents(g);//calls super-class   Color black = new Color(0,0,0);//creates color Black   Color white = new Color(255,255,255);  setBackground(black); // Sets the background   setForeground(white);  g.drawString("Welcome to Immortal Online ",10,50);    g.drawString("You see a town ahead."+"\n"+"Type 'Straight' and hit enter to go to town,'right' to go to the field,"+"\n"+" or 'left' to go to the forest.",10,65); text = inputField.getText(); if (text.equalsIgnoreCase("text"))  {   g.drawString("You are now in town", 10, 85);  g.drawString("What do you want to do",10, 95);  } inputField.addKeyListener(new KeyListener() {  @Override  public void keyTyped(KeyEvent arg0) {  }    @Override  public void keyReleased(KeyEvent arg0) {  }    @Override  public void keyPressed(KeyEvent arg0) { if(arg0.getKeyCode() == KeyEvent.VK_ENTER) {messageArea.insert(inputField.getText() + "\n", messageArea.getText().length());inputField.setText("");messageArea.insert("Message processed\n", messageArea.getText().length()); }  }   });    }};  opps sorry about that i was trying to put my code in a box like you did.   