package edu.school.elevator;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JButton;
import java.awt.Font;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import com.jgoodies.forms.factories.DefaultComponentFactory;
/**
 * Информатика, 8 клас, издателство Просвета, 2017
 * Автори: Светла Бойчева, Николина Николова, Елиза Стефанова, Антон Денев
 * 3.1.3. Реални типове данни
 * Урок: Реални типове данни – упражнение
 * Задача:Според рекордите на Гинес най-бързият и
 * най-дълъг асансьор в света през 2016 г. е бил
 * този в Шанхайската кула. Той се изкачва на височина 632 метра за 53 секунди.
 * Да се реализира приложение Elevator, което по
 * зададени разстояние и време да пресмята скоростта и ускорението на асансьор.
 * 
 * Версия 1.
 */
public class ElevatorFrame extends JFrame {

	private JPanel contentPane;
	private JTextField txtDistance;
	private JTextField txtTime;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ElevatorFrame frame = new ElevatorFrame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public ElevatorFrame() {
		setTitle("\u0410\u0441\u0430\u043D\u0441\u044C\u043E\u0440");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 332, 330);
		contentPane = new JPanel();
		contentPane.setBackground(new Color(0, 191, 255));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		JLabel lblVelocity = new JLabel("\u0441\u043A\u043E\u0440\u043E\u0441\u0442");
		lblVelocity.setFont(new Font("Tahoma", Font.BOLD, 14));
		lblVelocity.setBounds(10, 246, 296, 14);
		contentPane.add(lblVelocity);

		JLabel lblAcceleration = new JLabel("\u0443\u0441\u043A\u043E\u0440\u0435\u043D\u0438\u0435");
		lblAcceleration.setFont(new Font("Tahoma", Font.BOLD, 14));
		lblAcceleration.setBounds(10, 211, 296, 14);
		contentPane.add(lblAcceleration);

		JButton btnCalc = new JButton("\u041F\u0420\u0415\u0421\u041C\u0415\u0422\u041D\u0418");
		btnCalc.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				double distance = Double.parseDouble(txtDistance.getText());
				double time = Double.parseDouble(txtTime.getText());

				double acceleration = 2.0 * distance / (time * time);
				double velocity = acceleration * time;

				lblAcceleration.setText("Ускорение: " + Double.toString(acceleration) + " m/s^2");
				lblVelocity.setText("   Скорост: " + Double.toString(velocity) + " m/s");
			}
		});
		btnCalc.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnCalc.setBounds(176, 11, 118, 50);
		contentPane.add(btnCalc);

		JButton btnClear = new JButton("\u0418\u0417\u0427\u0418\u0421\u0422\u0418");
		btnClear.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				lblAcceleration.setText("");
				lblVelocity.setText("");
				txtDistance.setText("");
				txtTime.setText("");

			}
		});
		btnClear.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnClear.setBounds(176, 72, 118, 50);
		contentPane.add(btnClear);

		JButton btnExit = new JButton("\u0418\u0417\u0425\u041E\u0414");
		btnExit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {

				System.exit(0);
			}
		});
		btnExit.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnExit.setBounds(176, 133, 118, 50);
		contentPane.add(btnExit);

		JLabel lblNewLabel = new JLabel("\u0432\u0438\u0441\u043E\u0447\u0438\u043D\u0430");
		lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 16));
		lblNewLabel.setBounds(10, 53, 127, 14);
		contentPane.add(lblNewLabel);

		txtDistance = new JTextField();
		txtDistance.setBounds(10, 81, 86, 20);
		contentPane.add(txtDistance);
		txtDistance.setColumns(10);

		JLabel lblM = new JLabel("m");
		lblM.setFont(new Font("Tahoma", Font.BOLD, 16));
		lblM.setBounds(106, 82, 31, 14);
		contentPane.add(lblM);

		JLabel label_1 = new JLabel("\u0432\u0440\u0435\u043C\u0435");
		label_1.setFont(new Font("Tahoma", Font.BOLD, 16));
		label_1.setBounds(10, 127, 127, 14);
		contentPane.add(label_1);

		txtTime = new JTextField();
		txtTime.setColumns(10);
		txtTime.setBounds(10, 155, 86, 20);
		contentPane.add(txtTime);

		JLabel lblS = new JLabel("s");
		lblS.setFont(new Font("Tahoma", Font.BOLD, 16));
		lblS.setBounds(106, 156, 31, 14);
		contentPane.add(lblS);

	}
}
