Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Main {
    public static void main(String[] argv) throws Exception {
        MyTextField component = new MyTextField(10);
        MyTextField component2 = new MyTextField(10);

        JPanel p = new JPanel();
        p.add(component);
        p.add(component2);
        JOptionPane.showMessageDialog(null, p);

    }
}

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();
            }
        });
    }
}