tags:

views:

49

answers:

2

i am buiding a small jframe with 2 lables and 2 textfields(Jtextfield1,Jtextfield2) and a jbutton .i want that when the user enters some data in the Jtextfield1,the data is retrieved from database regarding user and his details are displayed in the Jtextfield2. i know how to retrieve data from database but how to apply actionperformed to Jtextfield1.please help and give an example too.

+1  A: 

Here are the info that you need

For database see http://java.sun.com/docs/books/tutorial/jdbc/

For JTextField see http://java.sun.com/docs/books/tutorial/uiswing/components/textfield.html

Chuk Lee
+2  A: 

i want that when the user enters some data in the Jtextfield1,the data is retrieved from database

What does this mean? Does it mean:

a) that as a user types each character you want to query the database? If so, then add a DocumentListener to the Document of the text field

b) that when a user is finished typing you want to query the database? If so, then how does the program know when the user is finished typing? If the user is finished typing when

i) the Enter key is pressed, then add an ActionListener to the text field.

ii) the text field loses focus, then add a FocusListener to the text field.

Or are you simply talking about the user clicking a button when the text has been entered in both text fields? If so then you add an ActionListener to the button.

Also you can invoke the button even when focus isn't on the button by using the Enter key with the following code:

frame.getRootPane().setDefaultButton( button );

The question is too vague to give a specific answer.

camickr