title: How to get instantly update from the textfield?
body: <p>I want to change the input in the textfield which will instantly update to the display, instead of press <code>ENTER</code> button to update it.</p>
  
  <p>Here is my code.</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  import java.awt.event.*;
  
  public class MyProgram01 extends JFrame
  {
      private JTextField text1;
      private JCheckBox check1;
      private JCheckBox check2;
      private String message;
      private JLabel label1;
      private JLabel label2;
      private Font font;
  
      public MyProgram01(String title)
      {
          super(title);
          check1 = new JCheckBox("Bold");
          check2 = new JCheckBox("Italics");
  
          label1 = new JLabel("Text : ");
          label2 = new JLabel("Style : ");
          message = "Good Morning...";
          text1 = new JTextField(message, 100);
          font = new Font("Times New Roman", Font.PLAIN, 36);
          setBounds(0, 0, 600, 300);
  
          JPanel panel = new JPanel();
          panel.setLayout(null);
          panel.setBounds(0, 0, 600, 120);
          panel.setBackground(Color.ORANGE);
          label1.setFont(new Font("Times New Roman", Font.PLAIN, 36));
          label1.setBounds(15, 15, 100, 36);
          panel.add(label1);
          text1.setBounds(120, 15, 400, 36);
          panel.add(text1);
  
          label2.setFont(new Font("Times New Roman", Font.PLAIN, 36));
          label2.setBounds(15, 65, 100, 36);
          panel.add(label2);
          check1.setBounds(120, 65, 100, 36);
          check2.setBounds(220, 65, 100, 36);
          panel.add(check1);
          panel.add(check2);
  
          check1.addActionListener(new CheckBoxListener());
          check2.addActionListener(new CheckBoxListener());
          text1.addActionListener(new TextFieldListener());
  
          setLayout(null);
          add(panel);
      }
      public void paint(Graphics g)
      {
          super.paint(g);
  
          g.setFont(font);
          g.drawString(message, 15, 255);
  
      }
      private class CheckBoxListener implements ActionListener
      {
          public void actionPerformed(ActionEvent e)
          {
              if(check1.isSelected() &amp;&amp; check2.isSelected())
              {
                  font = new Font("Times New Roman", Font.BOLD + Font.ITALIC, 36);    
                  repaint();
              }
              else if(check1.isSelected())
              {
                  font = new Font("Times New Roman", Font.BOLD, 36);
                  repaint();
              }
              else if(check2.isSelected())
              {
                  font = new Font("Times New Roman", Font.ITALIC, 36);
                  repaint();
              }
              else
              {
                  font = new Font("Times New Roman", Font.PLAIN, 36);
                  repaint();
              }
          }
      }
      private class TextFieldListener implements ActionListener
      {
          public void actionPerformed(ActionEvent e)
          {
              message = text1.getText();
              repaint();
          }
      }
      public static void main(String[] args)
      {
          JFrame frame = new MyProgram01("My Program 01");
          frame.setVisible(true);
          frame.setResizable(true);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      }
  }    
  </code></pre>
  
  <p>How can I change the code to instantly update to the display?</p>
  
  <p>EDIT : </p>
  
  <p>It's work with the keyListener, but my program will only start display after second key is pressed.</p>
  
  <p>For example, I key in <code>abc</code>, the program will start show <code>a</code> when I press <code>b</code>, and when I pressed <code>c</code>, it displays <code>ab</code> and <code>c</code> is missing, unless I press <code>ENTER</code>.</p>
  
  <p>Here the part of the code : </p>
  
  <pre><code>text1.addKeyListener(new KeyAdapter()
      {
              public void keyPressed(KeyEvent e)
              {
                  message = text1.getText();
                  repaint();
              }
      });
  </code></pre>