title: call an object in an ActionListener don't work, but work in the object class main
body: <p>I'm writing a java image panel, to make some stuff with images in java. It's a first shot, to see how I can do things better.</p>
  
  <p>So I wrote those three Classes and the problem is when I use the class <code>Diaporama</code> (you can see the code below) in the class <code>MainWindow</code> I have nothing shown.
  But if i use the <code>public static void main (String [] args)</code> in the class Diaporama, everything is working.</p>
  
  <pre><code>/**RechercheFichier.java*/
  //this class while return an ArrayList of String which contain all file path selected
  
  public class RechercheFichier {
  
      private JFileChooser myFileChooser;
      private ArrayList&lt;String&gt; FileList;
  
      public RechercheFichier() {
          myFileChooser = new JFileChooser();
          myFileChooser.setCurrentDirectory(new File("."));
          myFileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
          try {
              int value = myFileChooser.showOpenDialog(null);
              if (value == JFileChooser.APPROVE_OPTION) {
                  File SelectedFile = myFileChooser.getSelectedFile();
                  String Filename = SelectedFile.getPath();
                  FileList = new ArrayList&lt;String&gt;();
                  if (SelectedFile.isDirectory()) {
                      String[] myFile = SelectedFile.list();
                      for (int i = 0; i &lt; myFile.length; i++) {
                          if (myFile[i].endsWith(".png") == true
                                  || myFile[i].endsWith(".jpg") == true
                                  || myFile[i].endsWith(".jpeg") == true) {
                              FileList.add(Filename + "/" + myFile[i]);
                          }
                      }
                  } else
                      FileList.add(Filename);
              } else
                  JOptionPane.showMessageDialog(null,
                          "User did not choose a file.");
          } catch (Exception e) {
              JOptionPane.showMessageDialog(null, e.getMessage(), "Error",
                      JOptionPane.ERROR_MESSAGE);
          }
      }
  
      //getter and setter
      public ArrayList&lt;String&gt; getFileList() {
          return FileList;
      }
  
      public void setFileList(ArrayList&lt;String&gt; fileList) {
          FileList = fileList;
      }
  </code></pre>
  
  <p>Diaporama class:</p>
  
  <pre><code>/**Diaporama.java*/ 
  public class Diaporama extends JFrame {
  
      private JFrame frame;
      private JPanel panel;
      private JLabel lab;
  
      public Diaporama() {
          frame =  new JFrame();
          panel = new JPanel();
          lab = null;
          frame.setTitle("Diaporama");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          RechercheFichier file = new RechercheFichier();
          ArrayList&lt;String&gt; toto = file.getFileList(); //toto contain all file path
          //Collections.sort(toto);
          for (int i = 0; i &lt; toto.size(); i++) {
              panel = new JPanel();
              frame.setLayout(new GridLayout(1,1));
              frame.setVisible(true);
              frame.setSize(600, 500);
              frame.setLocation(200, 200);
              // this.image = getToolkit().getImage(toto.get(i));
              System.out.println(toto.get(i));
              this.lab = new JLabel(new ImageIcon(toto.get(i)));
              panel.add(lab);
              frame.setContentPane(panel);
              try {
                  Thread.sleep(2000L);
              } catch (InterruptedException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
  
              // imagePanel.remove(imagePanel);
              panel.remove(lab);
              panel.revalidate();
              frame.pack();
  
              frame.repaint();
              panel = null;
          }
          frame.dispose();
      }
  
      //public static void main(String [] args)
      //{
      //  new Diaporama();
      //}
  </code></pre>
  
  <p>MainWindow class:</p>
  
  <pre><code>/** MainWindow.java**/
  public class MainWindow extends JFrame implements ActionListener{
  
      private JFrame frame;
      private JButton buttonDiapo, buttonOpen, buttonSearch, buttonTag, buttonAlbum, buttonQuit;
      private JPanel panel;
  
      public JFrame getFrame()
      {
          return frame;
      }
  
      public MainWindow()
      {
              frame = new JFrame("The best Jphoto");
              frame.setSize(300, 400);
              frame.setLocation(200, 200);
              buttonDiapo = new JButton("Diaporama");
              buttonOpen = new JButton("Ouvrir Photo");
              buttonQuit = new JButton ("Quitter");
              buttonSearch = new JButton("Recherche par tag");
              buttonTag = new JButton("Add tag");
              buttonAlbum = new JButton("Creer un album");
              panel = new JPanel();
              panel.setLayout(new FlowLayout());
              panel.add(buttonOpen);
              panel.add(buttonDiapo);
              panel.add(buttonAlbum);
              panel.add(buttonSearch);
              panel.add(buttonTag);
              panel.add(buttonQuit);
              frame.getContentPane().add(panel, BorderLayout.CENTER);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.pack();
              frame.setVisible(true);
              //ajout du action Listener pour le bouton Open
              buttonOpen.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      // new OpenImg();
                  }
              });
              //ajout du action Listener pour le bouton Diapo
              buttonDiapo.addActionListener(new ActionListener() {
                  @Override
                  public void actionPerformed(ActionEvent e) {
                                //the problem is here
                       new Diaporama();
  
                  }
              });
              buttonQuit.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      System.exit(0);
                  }
              });
  
              buttonAlbum.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      // new Album();
                  }
              });
  
              buttonSearch.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      // new Search();
                  }
              });
  
              buttonTag.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      // new Tag();
                  }
              });
          }
  
  
          public static void main(String[] args) {
              // Set the look and feel to Java Swing Look
              new MainWindow();
          }
  
  
          @Override
          public void actionPerformed(ActionEvent e) {
              // TODO Auto-generated method stub
  
          }
  }
  </code></pre>