title: Why doesn't the String object display that gets pressed key characters appended to it?
body: <p>I wrote a Java applet code using Key Event handling to demonstrate Non buffered input in Java. My code is working fine and the output is alright but I'm having trouble accomplishing another objective in this program: in the overriden <strong>keyPressed()</strong> method, I write the line: <strong>showStatus(s);</strong> , where <strong>s</strong> is the global static StringBuffer object which the characters typed from the keyboard are appended to. But the <strong>showStatus()</strong> method displays text on the status bar of the applet viewer. Therefore, the present program is usable only in an applet viewer and not in a web browser. I tried putting the statement <strong>g.drawString(String.valueOf(s),10,90);</strong> <em>(<strong>g</strong>=Graphics class object as argument of paint())</em> in the <strong>paint()</strong> method to display the text in the canvas. I expected this to work as s is global and static but it's not showing any output. I used the <strong>drawString()</strong> method in <strong>paint()</strong> both with and without overriding the <strong>boolean action()</strong> method but I still didn't get anything. I just want help in displaying the typed text in the canvas of the applet.  </p>
  
  <p>Below is my code. Please view it for reference and to help me out the best way possible. Thank you.</p>
  
  <pre><code>/* An applet that implements the concept of non buffered user input
  using Event handling method.
  */
  
  import java.applet.*;
  import java.awt.*;
  import java.awt.event.*;
  
  public class NonBufferInput extends Applet implements KeyListener {
      public static StringBuffer s;
  
      @Override
      public void init() {
          addKeyListener(this);
          s=new StringBuffer();
      }//init
  
      @Override
      public void keyTyped(KeyEvent K) {}
  
      @Override
      public void keyPressed(KeyEvent K) {
         char c=K.getKeyChar();
         int i=K.getKeyCode();
         if(i==32)  //space bar
             s.append(' ');
         else if(i==10||i==16||i==20||i==32||i==17||i==524||i==18||i==525||i==27
               ||(i&gt;=112&amp;&amp;i&lt;=123)||i==145||i==19||i==155||i==36||i==33||i==127
               ||i==35||i==34||i==144||(i&gt;=37&amp;&amp;i&lt;=40));  //characters I don't want as input
         else if(i==8) {  //backspace
             if(s.length()!=1)
                 s.setLength(s.length()-1);
         }
         else
             s.append(c);
         showStatus("Typed : "+s);
      }
  
      @Override
      public void keyReleased(KeyEvent K) {}
  
      @Override
      public void paint(Graphics g) {
          g.drawString("Text will be displayed on status bar as you type.",10,50);
          g.setColor(Color.blue);
          g.drawString(String.valueOf(s),10,80); //PROBLEM
      }//paint
  
      @Override
      public boolean action(Event event, Object obj) {
          repaint();
          return true;
      }//action
  }//class
  </code></pre>