import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.Component;
/* This class uses GUI to create a Van or a Sports Car
 * object and print its relative values
 */
public class GUI extends JFrame implements ActionListener // Class extending JFrame with ActionListener implemented
{
    JPanel pnl = new JPanel(); // 1st panel
    JPanel pnl1 = new JPanel(); // 2nd panel
    JButton Van = new JButton("Van"); // Van button
    JButton spCar = new JButton("Sport Car"); // Sports Car button
    JTextArea txt = new JTextArea(); // Text Area, will show the vehicle details

    public GUI()
    {
        setSize(250,250); // Set Frame size
        setVisible(true); // Frame visible
        setLayout(new BorderLayout()); // set Frame layout
        Van.addActionListener(this); // add listener to the Van button
        spCar.addActionListener(this); // add listener to the Sports Car button
        pnl.add(Van); // add Van button to 1st panel
        pnl.add(spCar); // add Sport Car button to 1st panel
        pnl1.add(txt); // add Text Area to 2nd panel
        add("North",pnl); // add 1st panel to the North part of the Frame
        add("Center",pnl1); // add 2nd panel to the Center part of the Frame
    }

    public static void main (String args[])
    {
        GUI gui = new GUI(); // class calls an object of itself
    }

    public void actionPerformed(ActionEvent e)
    {
        if (e.getActionCommand().toString().equals("Sport Car")) // create a Sports Car if relative button is pressed
        {
            Vehicle car1 = new SportCar(200,1500,220); // create Sport Car
            SportCar Car1 = (SportCar)car1; // casting
            String carConsumption = "SPORTS CAR" + "\nFUEL CONSUMPTION: " + Math.round(Car1.consumption())+"\n"+
                "ACCELERATION: " + car1.acceleration() +"\n"+
                "Horsepower: " + car1.getHorsepower()+"\n" + 
                "Weight: " + car1.getWeight()+"\n"+ 
                "Aerodynamics: "+ car1.getAerodynamics();
            txt.setText(carConsumption); // edit the Text Area
        }
        else if(e.getActionCommand().toString().equals("Van")) // create a Van if relative button is pressed
        {
            Vehicle van = new Van(100,3500,160.4); // create Van
            Van Van = (Van) van; // casting
            String vanAcceleration = "VAN"+"\nACCELERATION: " + Math.round(Van.acceleration())+" mph\n"+ 
                "Horsepower: " + van.getHorsepower()+"\n" + 
                "Weight: " + van.getWeight()+"\n"+ 
                "Aerodynamics: "+ van.getAerodynamics();
            txt.setText(vanAcceleration); // edit the Text Area            
        }
    }
}