import java.io.File;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import java.io.IOException;
import java.util.Scanner;

// This example illustrates opening a text file and reading lines one at a time
// and then picking out the "words" on the line. It also shows how to have scrollable
// output

public class Example3 {
    // The throws Exception clause is need when doing file I/O
    public Example3() throws IOException {
        String fileName = JOptionPane.showInputDialog("Enter the input file name","src/Example3.java");
        Scanner fileScanner = new Scanner(new File(fileName));
        String out = "";
        while( fileScanner.hasNext() ) {
            // The default delimiters are the white space characters
            String nextWord = fileScanner.next();
            out += "   " + nextWord + "\n";
        } // end while
        // The following area will have 25 rows and 40 columns for the output String out
        JTextArea outArea = new JTextArea(out,30,40);
        JOptionPane.showMessageDialog(null,new JScrollPane(outArea));
    } // end Example3()
    
    public static void main(String[] args) throws IOException {
        new Example3();
    } // end main
    
} // end Example3
