import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*; 
import java.io.*;

class OplossingHoofdstuk17Opgave5 extends JFrame
    implements  ActionListener {

    private JTextArea textArea1,textArea2;
    private JButton Button;
    private BufferedReader inFile1,inFile2;
    private JTextField nameField1,nameField2;
    private JLabel nameLabel1,nameLabel2;
    private String regel1,regel2;

    public static void main (String [] args) {
        OplossingHoofdstuk17Opgave5 frame = new OplossingHoofdstuk17Opgave5();

        frame.setSize(500, 400);
        frame.createGUI();
        frame.show();
    }

    private void createGUI() {
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        Container window = getContentPane();
        window.setLayout(new FlowLayout());

        nameLabel1 = new JLabel("File1 name:  ");
        window.add(nameLabel1);

        nameField1 = new JTextField(10);
        window.add(nameField1);
        nameField1.addActionListener(this);

        textArea1 = new JTextArea("",3,25);
        JScrollPane scrollPane1 = new JScrollPane(textArea1);
        window.add(scrollPane1);

        nameLabel2 = new JLabel("File2 name:  ");
        window.add(nameLabel2);

        nameField2 = new JTextField(10);
        window.add(nameField2);
        nameField2.addActionListener(this);

        textArea2 = new JTextArea("",3,25);
        JScrollPane scrollPane2 = new JScrollPane(textArea2);
        window.add(scrollPane2);                        
        
        Button = new JButton("open");
        window.add(Button);
        Button.addActionListener(this);
        
        
        
        
    }

    public void actionPerformed(ActionEvent event) {
        if (event.getSource() == Button) {
            try {
                inFile1 = new BufferedReader(
                    new FileReader(nameField1.getText()));
                textArea1.setText( "");    // clear the input area
                String line;
                while ( ( line = inFile1.readLine()) != null) {
                    regel1 = line;
                    textArea1.append(line+"\n");
                }
                inFile1.close();
            }
            catch (IOException e) {
                JOptionPane.showMessageDialog(null, 
                    "File Error: " + e.toString());
            }
            
            try {
                inFile2 = new BufferedReader(
                    new FileReader(nameField2.getText()));
                textArea2.setText( "");    // clear the input area
                String line;
                while ( ( line = inFile2.readLine()) != null) {
                    regel2 = line;
                    textArea2.append(line+"\n");
                }
                inFile2.close();
            }
            catch (IOException e) {
                JOptionPane.showMessageDialog(null, 
                    "File Error: " + e.toString());
            }
            
            
            if (regel1.equals(regel2)) {
            	
            	JOptionPane.showMessageDialog(null,"De twee eerste regels zijn gelijk!");
            }
            
            
        }
    }
}




