title: Where to put java code when using Jframe?
body: <p>I have created a java code which uses diff and compares files contained in two folders.</p>
  
  <p>I used diff utilities for using diff command on Windows.</p>
  
  <p>I got to know about JFileChooser and Now I am trying to give a GUI to my code. Now my concern is where should i put my Java Code so that when i select two files or select two folders, diff works on them.</p>
  
  <p>Below is the code for JfileChooser</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  import java.io.*;
  import javax.swing.*;
  
  public class SimpleFileChooser extends JFrame {
  
     public SimpleFileChooser() {
      super("File Diffrence Finder");
      setSize(350, 200);
      setDefaultCloseOperation(EXIT_ON_CLOSE);
  
      Container c = getContentPane();
      c.setLayout(new FlowLayout());
  
      JButton openButton1 = new JButton("Open File 1");
      JButton openButton2 = new JButton("Open File 2");
      JButton dirButton1 = new JButton("Pick Folder 1");
      JButton dirButton2 = new JButton("Pick Folder 2");
      final JLabel statusbar = 
                   new JLabel("Output of your selection will go here");
  
      // Create a file chooser that opens up as an Open dialog
      openButton1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
          JFileChooser chooser = new JFileChooser();
          chooser.setMultiSelectionEnabled(true);
          int option = chooser.showOpenDialog(SimpleFileChooser.this);
          if (option == JFileChooser.APPROVE_OPTION) {
            File[] sf = chooser.getSelectedFiles();
            String filelist = "nothing";
            if (sf.length &gt; 0) filelist = sf[0].getName();
            for (int i = 1; i &lt; sf.length; i++) {
              filelist += ", " + sf[i].getName();
            }
            statusbar.setText("You chose " + filelist);
          }
  
        }
      });
  
      // Create a file chooser that opens up as an Open dialog
      openButton2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
          JFileChooser chooser = new JFileChooser();
          chooser.setMultiSelectionEnabled(true);
          int option = chooser.showOpenDialog(SimpleFileChooser.this);
          if (option == JFileChooser.APPROVE_OPTION) {
            File[] sf = chooser.getSelectedFiles();
            String filelist = "nothing";
            if (sf.length &gt; 0) filelist = sf[0].getName();
            for (int i = 1; i &lt; sf.length; i++) {
              filelist += ", " + sf[i].getName();
            }
            statusbar.setText("You chose " + filelist);
          }
  
        }
      });
  
  
      // Create a file chooser that allows you to pick a directory
      // rather than a file
      dirButton1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
          JFileChooser chooser = new JFileChooser();
          chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
          int option = chooser.showOpenDialog(SimpleFileChooser.this);
          if (option == JFileChooser.APPROVE_OPTION) {
            statusbar.setText("You opened " + ((chooser.getSelectedFile()!=null)?
                              chooser.getSelectedFile().getName():"nothing"));
          }
          else {
            statusbar.setText("You canceled.");
          }
        }
      });
  
      // Create a file chooser that allows you to pick a directory
      // rather than a file
      dirButton2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
          JFileChooser chooser = new JFileChooser();
          chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
          int option = chooser.showOpenDialog(SimpleFileChooser.this);
          if (option == JFileChooser.APPROVE_OPTION) {
            statusbar.setText("You opened " + ((chooser.getSelectedFile()!=null)?
                              chooser.getSelectedFile().getName():"nothing"));
          }
          else {
            statusbar.setText("You canceled.");
          }
        }
      });
  
      c.add(openButton1);
      c.add(openButton2);
      c.add(dirButton1);
      c.add(dirButton2);
      c.add(statusbar);
    }
  
    public static void main(String args[]) {
      SimpleFileChooser sfc = new SimpleFileChooser();
      sfc.setVisible(true);
    }
  }
  </code></pre>
  
  <p>Diff Code : </p>
  
  <pre><code>import java.io.File;
  import java.util.*;
  
  public class ListFiles
  {
  
      public static void main(String[] args) 
      {
  
          String path1 = "C:\\Users\\hi\\Downloads\\IIT Typing\\IIT Typing"; 
  
          String path2 = "C:\\Users\\hi\\Downloads\\IIT Typing\\IIT Typing"; 
  
          File folder1 = new File(path1);
          File folder2 = new File(path2);
  
          ArrayList&lt;String&gt; commonfiles = new ArrayList&lt;&gt;();
  
          List&lt;File&gt; filesList1 = Arrays.asList(folder1.listFiles());
      List&lt;File&gt; filesList2 = Arrays.asList(folder2.listFiles()); 
  
  
      for (File f1 : filesList1)
      {
          if(f1.isFile())
          {
          for (File f2 : filesList2) 
          {
              if(f2.isFile() &amp;&amp; f1.getName().equals(f2.getName()))
              {
                        System.out.println(diff f1 f2);
              }
          }
      }
  } 
  }
  }
  </code></pre>