title: Getting Input from JTextArea
body: <pre><code>public static void main(String[] args) throws PrinterException {
  
      Toolkit tk = Toolkit.getDefaultToolkit();
      int xSize = ((int) tk.getScreenSize().getWidth());
      int ySize = ((int) tk.getScreenSize().getHeight());
      final String password = "Alphabet";
  
      JFrame screen = new JFrame("INSERT TITLE HERE");
  
      screen.setSize(xSize, ySize);
      screen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      screen.setResizable(false);
  
      screen.setVisible(true);
  
      final JWindow window = new JWindow(screen);
      window.setSize(xSize, ySize);
      window.setName("INSERT TITLE HERE");
  
      final JTextArea text = new JTextArea();
      text.setText("Type the password &gt; ");
      text.setBackground(Color.BLACK);
      text.setForeground(Color.green);
  
  
  
      window.add(text);
      window.setVisible(true);
  
      text.addKeyListener(new java.awt.event.KeyAdapter(){
          public void keyReleased(java.awt.event.KeyEvent evt) {
              System.out.println(evt.getKeyCode());
  
              if(evt.getKeyCode() == 51){
                  System.out.println(text.getText());
                  String passAttempt = text.getText();
                  int start = passAttempt.indexOf('&gt;') + 2 ;
                  int end = passAttempt.indexOf('#');
                  passAttempt = passAttempt.substring(start, end);
                  if(passAttempt.equals(password)) {
                      System.out.println("SUCCESSFUL");
                      text.setText("Login Successful");
                      window.add(text);
                      window.setVisible(true);
                      }
                  if(!passAttempt.equals(password)) {
                      System.out.println(passAttempt);
                      text.setText("Incorrect");
                      window.add(text);
                      window.setVisible(true);                        
                  } 
                  }
      }
  
      });
  }
  </code></pre>
  
  <p>I'm trying to create a fallout-esque user interface, and I need to get user input to type in a 'password' before I open up the UI, but I can't figure out how to read input from the JTextArea, please help!</p>
  
  <p>NOTE: The main goal here is to keep the feel of using an old school DOS program, so i can't use JOptionPane or anything like that.</p>
  
  <p>EDIT: Thanks for all your help everybody, I ended up going with the keyListener, and it worked perfectly! </p>