hi,
import java.awt.*;
import javax.swing.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
public class TextDisplayDemo extends JFrame {
public TextDisplayDemo() throws HeadlessException {
initComponents();
}
protected void initComponents() {
setSize(300, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setLayout(new FlowLayout(FlowLayout.LEFT));
Label label1 = new Label("TextField1: ");
final TextField text1 = new TextField(15);
Label label2 = new Label("TextField2: ");
final TextField text2 = new TextField(15);
text1.setPreferredSize(new Dimension(100, 20));
text2.setPreferredSize(new Dimension(100, 20));
getContentPane().add(label1);
getContentPane().add(text1);
getContentPane().add(label2);
getContentPane().add(text2);
text1.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent e) {
String text = text1.getText();
if(text.equals("")){
System.out.println("Enter the value");
}
else{
text2.setText(text);
}
}
public void keyTyped(KeyEvent e) {
}
public void keyPressed(KeyEvent e) {
}
});
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new TextDisplayDemo().setVisible(true);
}
});
}
}
------------------------------------------
Visit for more information,
http://www.roseindia.net/java/example/java/awt/Thanks.