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 java.awt.Color;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.SwingConstants;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.AbstractButton;
import javax.swing.BoxLayout;
import javax.swing.border.BevelBorder;
import javax.swing.UIManager;
import javax.swing.border.SoftBevelBorder;
import java.awt.SystemColor;

/**
 * Информатика, 8 клас, издателство Просвета, 2017
 * Автори: Светла Бойчева, Николина Николова, Елиза Стефанова, Антон Денев
 * Урок 3.1.2. Целочислени типове данни
 * Задача: Да се направи приложение, което да пресмята
 * периметъра на правоъгълник, ако дължините
 * на страните са зададени като целочислени
 * стойности в сантиметри.
 * 
 * Вариант 1.
 */
public class Shapes extends JFrame {

	private JPanel contentPane;
	private JTextField txtSideA;
	private JTextField txtSideB;

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

	/**
	 * Create the frame.
	 */
	public Shapes() {
		setTitle("Perimeter");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 337, 250);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBackground(new Color(0, 128, 128));
		panel.setBounds(10, 11, 172, 127);
		contentPane.add(panel);
		panel.setLayout(new BorderLayout(0, 0));
		
		JPanel panel_1 = new JPanel();
		panel_1.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		panel_1.setBackground(new Color(252, 252, 250));
		panel_1.setBounds(10, 134, 172, 66);
		contentPane.add(panel_1);
		panel_1.setLayout(null);
		
		
		JPanel panel_3 = new JPanel();
		panel_3.setBackground(new Color(255, 190, 189) );
		panel.add(panel_3, BorderLayout.CENTER);
		panel_3.setLayout(null);
		
		JLabel lblNewLabel_2 = new JLabel("a=");
		lblNewLabel_2.setBounds(26, 50, 20, 20);
		lblNewLabel_2.setForeground(Color.BLACK);
		lblNewLabel_2.setFont(new Font("Tahoma", Font.PLAIN, 16));
		panel_3.add(lblNewLabel_2);
		
		txtSideA = new JTextField();
		txtSideA.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		txtSideA.setBackground(new Color(255, 190, 189));
		txtSideA.setBounds(59, 52, 86, 20);
		panel_3.add(txtSideA);
		txtSideA.setColumns(10);
		
		JLabel lblB = new JLabel("b=");
		lblB.setBounds(26, 75, 28, 20);
		lblB.setForeground(Color.BLACK);
		lblB.setFont(new Font("Tahoma", Font.PLAIN, 16));
		panel_3.add(lblB);
		
		txtSideB = new JTextField();
		txtSideB.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		txtSideB.setBackground(new Color(255, 190, 189));
		txtSideB.setBounds(59, 77, 86, 20);
		txtSideB.setColumns(10);
		panel_3.add(txtSideB);
		
		JLabel lblNewLabel_1 = new JLabel("\u041F\u0440\u0430\u0432\u043E\u044A\u0433\u044A\u043B\u043D\u0438\u043A");
		lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD, 16));
		lblNewLabel_1.setBounds(0, 11, 172, 14);
		panel_3.add(lblNewLabel_1);
		
		JLabel lblPerimeter = new JLabel("?");
		lblPerimeter.setBounds(64, 25, 91, 14);
		panel_1.add(lblPerimeter);
		lblPerimeter.setForeground(Color.BLACK);
		lblPerimeter.setFont(new Font("Tahoma", Font.PLAIN, 16));
		
		JButton btnCalc = new JButton("\u041F\u0440\u0435\u0441\u043C\u0435\u0442\u043D\u0438");
		btnCalc.setToolTipText("\u041F\u0440\u0435\u0441\u043C\u044F\u0442\u0430 \u043F\u0435\u0440\u0438\u043C\u0435\u0442\u044A\u0440\u0430");
		btnCalc.setFont(new Font("Tahoma", Font.BOLD, 14));
		btnCalc.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent e) {
				
                int sideA = Integer.parseInt(txtSideA.getText());			
				int sideB = Integer.parseInt(txtSideB.getText());	
				
				int perimeter = 2 * (sideA + sideB);
				
				lblPerimeter.setText(Integer.toString(perimeter));	
				
			}
		});
		btnCalc.setForeground(new Color(0, 0, 0));
		btnCalc.setBackground(SystemColor.controlHighlight);
		btnCalc.setBounds(195, 11, 116, 44);
		contentPane.add(btnCalc);

		
		JButton btnClear = new JButton("\u0418\u0437\u0447\u0438\u0441\u0442\u0438");
		btnClear.setToolTipText("\u0418\u0437\u0447\u0438\u0441\u0442\u0432\u0430 \u0434\u044A\u043B\u0436\u0438\u043D\u0438\u0442\u0435 \u043D\u0430 \u0441\u0442\u0440\u0430\u043D\u0438\u0442\u0435 \u0438 \u0440\u0435\u0437\u0443\u043B\u0442\u0430\u0442\u0430");
		btnClear.setFont(new Font("Tahoma", Font.BOLD, 14));
		btnClear.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				lblPerimeter.setText("?");
			
				txtSideA.setText("");
				txtSideB.setText("");
			}
			
		});
		btnClear.setForeground(Color.BLACK);
		btnClear.setBackground(SystemColor.controlHighlight);
		btnClear.setBounds(195, 66, 116, 44);
		contentPane.add(btnClear);
		
		JButton btnExit = new JButton("\u0418\u0437\u0445\u043E\u0434");
		btnExit.setToolTipText(" \u0417\u0430\u0442\u0432\u0430\u0440\u044F \u043F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u0435\u0442\u043E");
		btnExit.setFont(new Font("Tahoma", Font.BOLD, 14));
		btnExit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				 System.exit(0);
			}
		});
		btnExit.setForeground(Color.BLACK);
		btnExit.setBackground(SystemColor.controlHighlight);
		btnExit.setBounds(195, 134, 116, 66);
		contentPane.add(btnExit);
		

		JLabel lblNewLabel = new JLabel("P=");
		lblNewLabel.setForeground(Color.BLACK);
		lblNewLabel.setBounds(30, 22, 24, 20);
		panel_1.add(lblNewLabel);
		lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 16));
		lblNewLabel.setBackground(Color.WHITE);
		
		

		
	
		

	}
}
