import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

/**
 * Class Cars - displays 10 different models of cars and images associated with them.
 * @author Atanas Ivanov 
 * CSCI 1130-01
 */

public class Cars extends JApplet implements ActionListener
{
    String []carsArray = new String [10];   //adding all the main components of the program
    
    Image []imageArray = new Image[10];
    JButton showcar;
    JLabel imagestring;
    JTextField input;
    ImageIcon icon;
    String userinput = " ";
    String infoUser;
    
    
    
    public void init()
    {
        setLayout (new BorderLayout () ); //setting the layout
        
        showcar = new JButton ("SHOW ME THE CAR!"); //adding a button that shows the desired vehicle
        
       
        input = new JTextField ("ENTER THE CAR YOU WANT TO SEE HERE:"); //instructions for the user
        
        
        
        
        imagestring = new JLabel  (" ");
        imagestring.setIcon(icon);
        
        add(showcar, BorderLayout. SOUTH);
        
        add(imagestring, BorderLayout. CENTER);
        add(input, BorderLayout. WEST);

        showcar.addActionListener (this);
        
        input.addActionListener (this);
        
        
        carsArray[0] = "Audi RS6"; //these are the different cars that are stored in the array
        carsArray[1] = "Audi RS7";
        carsArray[2] = "BMW M4";
        carsArray[3] = "Mercedes-Benz S65 AMG";
        carsArray[4] = "Ferrari 458 Italia";
        carsArray[5] = "Maserati Granturismo";
        carsArray[6] = "Lamborghini";
        carsArray[7] = "Bentley";
        carsArray[8] = "Range Rover";
        carsArray[9] = "Jaguar";

        

        imageArray[0] = getImage(getDocumentBase(), "Audi1.jpg"); // these are all the images of the 10 different cars in the program
        imageArray[1] = getImage(getDocumentBase(), "Audi2.jpg");
        imageArray[2] = getImage(getDocumentBase(), "BMW.jpg");
        imageArray[3] = getImage(getDocumentBase(), "Mercedes.jpg");
        imageArray[4] = getImage(getDocumentBase(), "Ferrari.png");
        imageArray[5] = getImage(getDocumentBase(), "Maserati.jpg");
        imageArray[6] = getImage(getDocumentBase(), "Lamborghini.png");
        imageArray[7] = getImage(getDocumentBase(), "bentley.jpg");
        imageArray[8] = getImage(getDocumentBase(), "Range.jpg");
        imageArray[9] = getImage(getDocumentBase(), "Jaguar.jpg"); 
          
    }

    
    public void actionPerformed (ActionEvent ae){ //creating the actionPerformed method
        Object obj = ae.getSource ();
        
              if (obj == showcar) {
                  
              userinput = input.getText();
                  
             for ( int i = 0; i < 10; i++) //
            {
                if(carsArray[i].equals(userinput)){icon = new ImageIcon(imageArray[i]); //here is the connection between the cars and their images
                    imagestring.setIcon(icon);
                    imagestring.setText(carsArray[i]);
                    break;
                }
                
                
            }

        
        
       

        }   
    }
}





 