MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

import java.awt.BorderLayout;
import java.io.FileReader;
import java.io.IOException;

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

public class MainClass {
    public static void main(String args[]) throws Exception {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JTextField nameTextField = new JTextField();
        frame.add(nameTextField, BorderLayout.NORTH);

        FileReader reader = null;
        try {
            reader = new FileReader("fileName.txt");
            nameTextField.read(reader, "fileName.txt");
        } catch (IOException exception) {
            System.err.println("Load oops");
            exception.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException exception) {
                    System.err.println("Error closing reader");
                    exception.printStackTrace();
                }
            }
        }

        frame.setSize(250, 100);
        frame.setVisible(true);
    }
}