title: GUI display info from ArrayList using JButton, JTextArea and showInputDialog
body: <p>Does anyone know how to iterate through an ArrayList and retrieve an item by using the actionPerformed method?</p>
  
  <p>Basically I'm trying to let the user click a button. After that button is clicked a showInputDialog appears, then the user for instance enters the id number of a student. All that student's details will appear in a jtextArea or showMessageDialog box.</p>
  
  <p>Can anyone show me?
  here is the actual code I was just using the student as example.</p>
  
  <pre><code>import java.util.*;
  import javax.swing.*;
  import javax.swing.event.*;
  import java.awt.*;
  import java.awt.event.*; 
  
  public class DepotAdmin 
  {
      private ArrayList&lt;Vehicle&gt; DepoVehicle = new ArrayList&lt;Vehicle&gt;(); 
      public DepotAdmin(String hd,String c, String m, String d,Fuel p,int EngSize)
      {
            DepoVehicle = new ArrayList&lt;Vehicle&gt;();
  
      }
  
  
       private void setupDepot(){
          //DepotArraylist vehicles = new DepotArraylist("1111","1111","1111","1111",new Fuel(""),0);
  
          DepoVehicle.add(new Car("BobMart","567890","Volvo","04/06/2014", new Fuel("Diesel"),6000));
          DepoVehicle.add(new Car("BobMart","465783","BMW","12/052014", new Fuel ("Petrol"), 8000));
          DepoVehicle.add(new Car("BobMart","348709","Ford","13/08/2014",new Fuel ("Petrol"), 3000));
          DepoVehicle.add(new Car("BobMart","145367","Lexus","18/08/2015",new Fuel ("Diesel"), 2000));
          DepoVehicle.add(new RentableCar("BobMart","847469","Citreon","08/07/2015",new             Fuel("Diesel"),1000));
          Car car1 = new Car("BobMart","567890","Volvo","04/06/2014", new Fuel("Diesel"),6000);
  
  
  
      public Vehicle byMake(String make)
      {
              String st[]=DepoVehicle.toArray(new String[DepoVehicle.size()]); 
                for ( Vehicle v : DepoVehicle)
           if (v.getMake().equals(make)){
              return v;
              }
             return null;
  
        }
  
  
  
  
      private JFrame Depot ;
      private JMenu Vehicles;
      private JMenu searchVehicle;    
      private JMenu rentVehicle;    
      private JMenu returnVehicle;
      private JMenuItem vehicles1;
      private JMenuItem searchVehicle1;
      private JMenuItem rentVehicle1;
      private JMenuItem returnVehicle1; 
      private JTextArea textArea;
      private JMenuBar menubar;
      private JList vList;
      private ResDepotAdmin listener;
      private ResDepotAdmin listener1;
      private ResDepotAdmin listener2;
      private ResDepotAdmin listener3;
      private JLabel repeatLabel;
      private JTextField inputText;
      private JPanel textPanel;
      public DepotAdmin(){
      //creating the frame to place the menu bar
      Depot = new JFrame ("Depot");
      //creating the menubar to place the menu items
      menubar = new JMenuBar();
      //set the menu bar in the frame
      Depot.setJMenuBar(menubar);
      //set the menus on the menu bar
      Vehicles = new JMenu ("vehicles");
      menubar.add(Vehicles);
      searchVehicle = new JMenu ("search");
      menubar.add(searchVehicle);
      rentVehicle = new JMenu ("rent");
      menubar.add(rentVehicle);
      returnVehicle = new JMenu ("return");
      menubar.add(returnVehicle);
      //set the menu items on the menues
      vehicles1 = new JMenuItem ("Vehicle List");
      Vehicles.add(vehicles1);
      searchVehicle1 = new JMenuItem ("Search Vehicle");
      searchVehicle.add(searchVehicle1);
      rentVehicle1 = new JMenuItem ("Rent Vehicle");
      rentVehicle.add(rentVehicle1);
      returnVehicle1 = new JMenuItem ("Return Vehicle");
      returnVehicle.add(returnVehicle1);
      //data display section
      textArea = new JTextArea(70,70);
      textPanel = new JPanel();
      //add textarea to panel
      textPanel.add(textArea);
      //add panel to frame
      Depot.add((textPanel),BorderLayout.CENTER);
      listeners to respond to click by uaer
      listener = new ResDepotAdmin();
      listener1 = new ResDepotAdmin();
      listener2 = new ResDepotAdmin();
      listener3 = new ResDepotAdmin();
      vehicles1.addActionListener(listener);
      searchVehicle1.addActionListener(listener1);
      rentVehicle1.addActionListener(listener2);
      returnVehicle.addActionListener(listener3);
  
  
      String vehicleMake = "make";
      //JOptionPane.showInputDialog(searchVehicle1,"Enter vehicle make");
      //set the size of the frame
      Depot.setSize(600,600);
      //aet the visibility of the frame
      Depot.setVisible(true);
      //prevent the running the the program on exit
      Depot.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
  
  
           }
           public class ResDepotAdmin implements ActionListener
      {
  
  
         private String make; 
       private void setupDepot(){
          DepotArraylist vehicles = new DepotArraylist("1111","1111","1111","1111",new Fuel(""),0);
          vehicles.addVehicle(new Car("BobMart","567890","Volvo","04/06/2014", new Fuel("Diesel"),6000));
          vehicles.addVehicle(new Car("BobMart","465783","BMW","12/052014", new Fuel ("Petrol"), 8000));
          vehicles.addVehicle(new Car("BobMart","348709","Ford","13/08/2014",new Fuel ("Petrol"), 3000));
          vehicles.addVehicle(new Car("BobMart","145367","Lexus","18/08/2015",new Fuel ("Diesel"), 2000));
          vehicles.addVehicle(new RentableCar("BobMart","847469","Citreon","08/07/2015",new Fuel("Diesel"),1000));
          Car car1 = new Car("BobMart","567890","Volvo","04/06/2014", new Fuel("Diesel"),6000);
  
  
  
  }
  
  
           public Vehicle findVehicle(String make)
            {
             for (Vehicle dv : DepoVehicle)
               if (dv.getMake().equals(make))
              return dv;
                return null;
              }
  
  
               public void actionPerformed(ActionEvent e)
               {
                         //DepotAdmin DepoVehicle = new DepotAdmin("null","null","null","null",new Fuel(""),0);
  
                         ArrayList&lt;Vehicle&gt; DepoVehicle = new ArrayList&lt;Vehicle&gt;();
                                 DepoVehicle.add(new Car("BobMart","567890","Volvo","04/06/2014",    new Fuel("Diesel"),6000));
                                 DepoVehicle.add(new Car("BobMart","348709","Ford","13/08/2014",new Fuel ("Petrol"), 3000));
  
  
                       if ( e.getSource() == vehicles1){
                       textArea.append(DepoVehicle.toString()+"\n"+"\n");
                       }
  
  
                       String make = JOptionPane.showInputDialog(null,"Enter vehicle make");
  
                        if (e.getSource()== searchVehicle1){
  
                             for ( Vehicle v : DepoVehicle){ if (v.getMake().equals(make)){
                                                          textArea.append(make);
  
                                                                    }
                                                       }
  
                       }
              }
        }
  }
  </code></pre>