package edu.school;

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

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.SystemColor;
import javax.swing.JComboBox;
import javax.swing.SwingConstants;
/**
 * Информатика, 8 клас, издателство Просвета, 2017
 * Автори: Светла Бойчева, Николина Николова, Елиза Стефанова, Антон Денев
 * Урок 3.1.4.2. Аритметични изрази, съдържащи различни типове данни
 * Задача: RxC001 е в Ню Йорк. Трябва да се придвижи бързо с такси в
 * Манхатън от едно място до друго. Чуди се кой ли маршрут
 * ще е по-къс? Направете приложение Manhattan, което по
 * зададени координати на две точки определя
 * разстоянието между тях.
 * 
 * Вариант 1.
 */
public class ManhattanFrame extends JFrame {

	private JPanel contentPane;
	private JTextField txtXA;
	private JTextField txtYA;
	private JTextField txtXB;
	private JTextField txtYB;

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

	/**
	 * Create the frame.
	 */
	public ManhattanFrame() {
		setTitle("Manhattan");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 406, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("\u043A\u043E\u043E\u0440\u0434\u0438\u043D\u0430\u0442\u0438 \u043D\u0430 \u0442\u043E\u0447\u043A\u0430 \u0410");
		lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblNewLabel.setBounds(10, 11, 188, 14);
		contentPane.add(lblNewLabel);
		
		txtXA = new JTextField();
		txtXA.setHorizontalAlignment(SwingConstants.RIGHT);
		txtXA.setBounds(49, 36, 133, 20);
		contentPane.add(txtXA);
		txtXA.setColumns(10);
		
		JLabel lblXa = new JLabel("XA");
		lblXa.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblXa.setBounds(10, 39, 36, 14);
		contentPane.add(lblXa);
		
		JLabel lblYa = new JLabel("YA");
		lblYa.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblYa.setBounds(10, 70, 36, 14);
		contentPane.add(lblYa);
		
		txtYA = new JTextField();
		txtYA.setHorizontalAlignment(SwingConstants.RIGHT);
		txtYA.setColumns(10);
		txtYA.setBounds(49, 67, 133, 20);
		contentPane.add(txtYA);
		
		JLabel lblB = new JLabel("\u043A\u043E\u043E\u0440\u0434\u0438\u043D\u0430\u0442\u0438 \u043D\u0430 \u0442\u043E\u0447\u043A\u0430 B");
		lblB.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblB.setBounds(10, 105, 188, 14);
		contentPane.add(lblB);
		
		JLabel lblXb = new JLabel("XB");
		lblXb.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblXb.setBounds(10, 133, 36, 14);
		contentPane.add(lblXb);
		
		txtXB = new JTextField();
		txtXB.setHorizontalAlignment(SwingConstants.RIGHT);
		txtXB.setColumns(10);
		txtXB.setBounds(49, 130, 133, 20);
		contentPane.add(txtXB);
		
		JLabel lblYb = new JLabel("YB");
		lblYb.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblYb.setBounds(10, 164, 36, 14);
		contentPane.add(lblYb);
		
		txtYB = new JTextField();
		txtYB.setHorizontalAlignment(SwingConstants.RIGHT);
		txtYB.setColumns(10);
		txtYB.setBounds(49, 161, 133, 20);
		contentPane.add(txtYB);
		
		JLabel lblDistance = new JLabel("\u0420\u0430\u0437\u0441\u0442\u043E\u044F\u043D\u0438\u0435 \u043C\u0435\u0436\u0434\u0443 A \u0438 B:");
		lblDistance.setFont(new Font("Tahoma", Font.BOLD, 16));
		lblDistance.setBounds(10, 189, 370, 26);
		contentPane.add(lblDistance);
		
		JButton btnCalc = new JButton("\u041F\u0420\u0415\u0421\u041C\u0415\u0422\u041D\u0418");
		btnCalc.setBackground(SystemColor.activeCaption);
		btnCalc.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				int xA = Integer.parseInt(txtXA.getText());
				int yA = Integer.parseInt(txtYA.getText());
				int xB = Integer.parseInt(txtXB.getText());
				int yB = Integer.parseInt(txtYB.getText());
				
				int distance = Math.abs(xA-xB) + Math.abs(yA-yB);
			
				lblDistance.setText("Разстояние между A и B: " +
				                    Integer.toString(distance));
				

				 
				
			}
		});
		btnCalc.setFont(new Font("Tahoma", Font.PLAIN, 16));
		btnCalc.setBounds(216, 11, 145, 45);
		contentPane.add(btnCalc);
		
		JButton btnClear = new JButton("\u0418\u0417\u0427\u0418\u0421\u0422\u0418");
		btnClear.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				txtXA.setText("");
				txtXB.setText("");				
				txtYA.setText("");				
				txtYB.setText("");				
			}
		});
		btnClear.setBackground(SystemColor.activeCaption);
		btnClear.setFont(new Font("Tahoma", Font.PLAIN, 16));
		btnClear.setBounds(216, 68, 145, 45);
		contentPane.add(btnClear);
		
		JButton btnClose = new JButton("\u0418\u0417\u0425\u041E\u0414");
		btnClose.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		btnClose.setBackground(SystemColor.activeCaption);
		btnClose.setFont(new Font("Tahoma", Font.PLAIN, 16));
		btnClose.setBounds(216, 131, 145, 45);
		contentPane.add(btnClose);
		

	}
}
