Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

1 Visitor Messages

  1. View Conversation
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;

    public class KeyEventDemo extends JFrame implements KeyListener{
    JTextField typingArea;
    JPanel con;

    public KeyEventDemo(String name){
    super(name);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(400,400);


    typingArea = new JTextField(20);
    typingArea.addKeyListener(this);

    con = new JPanel();
    add(con);
    con.add(typingArea);

    setVisible(true);
    }

    public static void main(String[] args) {
    new KeyEventDemo("Key Event Demo");
    }



    /** Handle the key typed event from the text field. */
    public void keyTyped(KeyEvent e) {

    //this will check for pressing enter key
    if(KeyEvent.VK_ENTER == e.getKeyChar()){

    //if enter key typed this code will execute
    String strToSearch = typingArea.getText().trim();
    //Write here code for passing string to search engine
    System.out.println("Search on net for '"+strToSearch+"'");

    }
    }


    public void keyPressed(KeyEvent e) {

    }

    public void keyReleased(KeyEvent e) {
    }




    }
Showing Visitor Messages 1 to 1 of 1
About Kingchika

Basic Information

Statistics


Total Posts
Total Posts
0
Posts Per Day
0
Visitor Messages
Total Messages
1
Most Recent Message
January 24th, 2011 02:23 AM
Total Thanks
Total Thanks
0
  • Thanked 0 Times in 0 Posts
General Information
Last Activity
April 12th, 2013 06:52 PM
Join Date
December 30th, 2010