MyFrame.java Source code

Java tutorial

Introduction

Here is the source code for MyFrame.java

Source

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JTextField;

class MyFrame extends JFrame {

    JTextField field1;

    public MyFrame() {
        field1 = new JTextField(10);
        getContentPane().add("Center", field1);
        addWindowListener(new WindowAdapter() {
            public void windowOpened(WindowEvent e) {
                field1.requestFocus();
            }
        });
        pack();
        setVisible(true);
    }

}

public class Main {
    public static void main(String[] argv) {
        MyFrame myFrame = new MyFrame();
    }
}