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.

Conversation Between DanBrown and Kingchika

2 Visitor Messages

  1. 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) {
    }




    }
  2. Hello Brown.
    Am new to java pro. And i 'll lk u to tell me how to write "enter key event in textfield"
    an action wt enterkey that will search the web or jdb when ever enter key is pressed.
Showing Visitor Messages 1 to 2 of 2