MyTextField.java Source code

Java tutorial

Introduction

Here is the source code for MyTextField.java

Source

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.JTextField;

class MyTextField extends JTextField {
    MyTextField(int len) {
        super(len);
        addKeyListener(new KeyAdapter() {
            public void keyPressed(KeyEvent evt) {
                int key = evt.getKeyCode();
                if (key == KeyEvent.VK_ENTER)
                    transferFocus();
            }
        });
    }
}