You are here:   HomeJava ProgrammingSwingMouseListener in Java Swing Example
by Dinesh Thakur Category: Swing

 

import javax.swing.*;

import java.awt.*;
import java.awt.event.*;
public class KeyFrameJavaExample extends JFrame implements KeyListener
{
       private JLabel prmpt = new JLabel("Type Something in the TextBox");
       private JLabel OutPutLbl = new JLabel("Key Typed:");
       private JTextField TxtFld = new JTextField(10);
       public KeyFrameJavaExample()
         {
             setTitle("Key Frame in Java Swing");
             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             setLayout(new BorderLayout());
             add(prmpt, BorderLayout.NORTH);
             add(TxtFld, BorderLayout.CENTER);
             add(OutPutLbl, BorderLayout.SOUTH);
             addKeyListener(this);
             TxtFld.addKeyListener(this);
        }
             public void keyTyped(KeyEvent e)
               {
                  char c = e.getKeyChar();
                  OutPutLbl.setText("Last Character you Typed : " + c);
               }
                  public void keyPressed(KeyEvent e)
                    {
                    }
                     public void keyReleased(KeyEvent e)
                        {
                          }
                     public static void main(String[] args)
                           {
                                 KeyFrameJavaExample keyFrame = new KeyFrameJavaExample();
                                     final int WIDTH = 250;
                        final int HEIGHT = 100;
                                 keyFrame.setSize(WIDTH, HEIGHT);
                                 keyFrame.setVisible(true);
                           }
  }

Key Frame  in Java Swing Example





Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to contact us.



What's New and Popular





Popular Article