
i have one txt field and one button.when i entere any test in testfield then only button should be enabled. i need for this
thanks in advance

import javax.swing.*;
import java.awt.event.*;
class TextFieldAndButton
{
public static void main(String[] args)
{
JFrame f=new JFrame();
JTextField text=new JTextField(20);
final JButton b=new JButton("Check");
b.setEnabled(false);
text.addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent keyEvent) {
b.setEnabled(true);
}
public void keyReleased(KeyEvent keyEvent) {
b.setEnabled(true);
}
public void keyTyped(KeyEvent keyEvent) {
b.setEnabled(true);
}
});
text.setBounds(10,10,150,20);
b.setBounds(10,30,100,20);
f.setLayout(null);
f.add(text);
f.add(b);
f.setVisible(true);
f.setSize(300,100);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.