import javax.swing.*;
import java.awt.*;
 
 
public class Input extends JFrame {
 
    private static final int FRAME_WIDTH = 590;
    private static final int FRAME_HEIGHT = 280;
 
    private static final int FIELD_WIDTH = 130;
    private static final int FIELD_HEIGHT = 30;
 
    private static final String ORIG_DIST = "Orig. Dist. (miles): ";
    private static final String HOURS = "Hours: ";
    private static final String MINUTES = "Minutes: ";
    private static final String SECONDS = "Seconds: ";
    private static final String NEW_DIST = "New Dist. (miles): ";
    private static final String UNIT = "miles";
 
    private static final String COMPUTE = "Compute";
    private static final String NEW_TIME = "Projected Time: ";
 
    private JLabel origDistLabel;
    private JLabel hoursLabel;
    private JLabel minutesLabel;
    private JLabel secondsLabel;
    private JLabel newDistLabel;
 
    public JTextField origDistField;
    public JTextField hoursField;
    public JTextField minutesField;
    public JTextField secondsField;
    public JTextField newDistField;
 
    private JButton compute;
    private JLabel timeLabel;
    public JLabel newTime;
 
    private Control control;
 
    public Input(Control c) {
        control = c;
        setSize(FRAME_WIDTH, FRAME_HEIGHT);
        setResizable(false);
        addComponents(getContentPane());
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setVisible(true);
    }
 
    private void addComponents(Container contentPane) {
        contentPane.setLayout(null);
 
        // Create and place the Labels and TextFields
        origDistLabel = new JLabel(ORIG_DIST);
        origDistLabel.setBounds(10, 10, FIELD_WIDTH, FIELD_HEIGHT);
        contentPane.add(origDistLabel);
        origDistField = new JTextField();
        origDistField.setBounds(10, 20 + FIELD_HEIGHT, FIELD_WIDTH, FIELD_HEIGHT);
        contentPane.add(origDistField);
 
        hoursLabel = new JLabel(HOURS);
        hoursLabel.setBounds(20 + FIELD_WIDTH, 10, FIELD_WIDTH, FIELD_HEIGHT);
        contentPane.add(hoursLabel);
        hoursField = new JTextField();
        hoursField.setBounds(20 + FIELD_WIDTH, 20 + FIELD_HEIGHT, FIELD_WIDTH,
FIELD_HEIGHT);
        contentPane.add(hoursField);
 
        minutesLabel = new JLabel(MINUTES);
        minutesLabel.setBounds(30 + 2 * FIELD_WIDTH, 10, FIELD_WIDTH, FIELD_HEIGHT);
        contentPane.add(minutesLabel);
        minutesField = new JTextField();
        minutesField.setBounds(30 + 2 * FIELD_WIDTH, 20 + FIELD_HEIGHT, FIELD_WIDTH,
FIELD_HEIGHT);
        contentPane.add(minutesField);
 
        secondsLabel = new JLabel(SECONDS);
        secondsLabel.setBounds(40 + 3 * FIELD_WIDTH, 10, FIELD_WIDTH, FIELD_HEIGHT);
        contentPane.add(secondsLabel);
        secondsField = new JTextField();
        secondsField.setBounds(40 + 3 * FIELD_WIDTH, 20 + FIELD_HEIGHT, FIELD_WIDTH,
FIELD_HEIGHT);
        contentPane.add(secondsField);
 
        newDistLabel = new JLabel(NEW_DIST);
        newDistLabel.setBounds(10, 10 + 3 * FIELD_HEIGHT, FIELD_WIDTH, FIELD_HEIGHT);
        contentPane.add(newDistLabel);
        newDistField = new JTextField();
        newDistField.setBounds(10, 20 + 4 * FIELD_HEIGHT, FIELD_WIDTH, FIELD_HEIGHT);
        contentPane.add(newDistField);
 
        timeLabel = new JLabel(NEW_TIME, JLabel.RIGHT);
        timeLabel.setBounds(20 + FIELD_WIDTH, 10 + 3 * FIELD_HEIGHT, FIELD_WIDTH,
FIELD_HEIGHT);
        contentPane.add(timeLabel);
        newTime = new JLabel("", JLabel.RIGHT);
        newTime.setBounds(20 + FIELD_WIDTH, 20 + 4 * FIELD_HEIGHT, FIELD_WIDTH, 
FIELD_HEIGHT);
        contentPane.add(newTime);
 
        // Add the Compute button and label
        compute = new JButton(COMPUTE);
        compute.setBounds((FRAME_WIDTH-FIELD_WIDTH)/2, FRAME_HEIGHT-3*FIELD_HEIGHT,
                           FIELD_WIDTH, FIELD_HEIGHT);
        compute.addActionListener(control);
        contentPane.add(compute);
    }
 
 
    public double getOrigDistance() {
 double distance = Double.parseDouble(origDistField.getText());
               return distance;
   }
 
    public int getHours() {
        //COMPLETE IN LAB
    }
 
    public int getMinutes() {
        //COMPLETE IN LAB
    }
 
    public int getSeconds() {
        //COMPLETE IN LAB
    }
 
    public double getNewDistance() {
        //COMPLETE IN LAB
    }

 
    public void update(String time) {
        newTime.setText(time);
    }
}

