package edu.school;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.SpringLayout;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.Font;
import javax.swing.JButton;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

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

	/**
	 * 
	 */
	private static final long serialVersionUID = -6130253026047024662L;
	private JPanel contentPane;
	private JTextField txtName;

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

	/**
	 * Create the frame.
	 */
	public MeetJavaFrame() {
		setTitle("\u0417\u0430\u043F\u043E\u0437\u043D\u0430\u0439 \u0441\u0435 \u0441 Java");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 392, 258);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		SpringLayout sl_contentPane = new SpringLayout();
		contentPane.setLayout(sl_contentPane);
		
		JLabel lblName = new JLabel("\u041A\u0430\u043A \u0441\u0435 \u043A\u0430\u0437\u0432\u0430\u0448?");
		JLabel lblGreeting1 = new JLabel("");
		JLabel lblGreeting2 = new JLabel("");
		
		lblName.setForeground(new Color(204, 102, 51));
		sl_contentPane.putConstraint(SpringLayout.WEST, lblName, 15, SpringLayout.WEST, contentPane);
		lblName.setFont(new Font("Tahoma", Font.PLAIN, 12));
		sl_contentPane.putConstraint(SpringLayout.NORTH, lblName, 10, SpringLayout.NORTH, contentPane);
		sl_contentPane.putConstraint(SpringLayout.SOUTH, lblName, 33, SpringLayout.NORTH, contentPane);
		contentPane.add(lblName);
		
		txtName = new JTextField();
		txtName.setForeground(new Color(51, 102, 102));
		sl_contentPane.putConstraint(SpringLayout.NORTH, txtName, 1, SpringLayout.SOUTH, lblName);
		sl_contentPane.putConstraint(SpringLayout.EAST, lblName, 0, SpringLayout.EAST, txtName);
		sl_contentPane.putConstraint(SpringLayout.WEST, txtName, 38, SpringLayout.WEST, contentPane);
		sl_contentPane.putConstraint(SpringLayout.EAST, txtName, -174, SpringLayout.EAST, contentPane);
		txtName.setFont(new Font("Tahoma", Font.PLAIN, 12));
		contentPane.add(txtName);
		txtName.setColumns(10);
		

		sl_contentPane.putConstraint(SpringLayout.NORTH, lblGreeting1, 21, SpringLayout.SOUTH, txtName);
		sl_contentPane.putConstraint(SpringLayout.SOUTH, lblGreeting1, -110, SpringLayout.SOUTH, contentPane);
		lblGreeting1.setForeground(new Color(204, 102, 51));
		sl_contentPane.putConstraint(SpringLayout.WEST, lblGreeting1, 15, SpringLayout.WEST, contentPane);
		sl_contentPane.putConstraint(SpringLayout.EAST, lblGreeting1, -10, SpringLayout.EAST, contentPane);
		lblGreeting1.setFont(new Font("Tahoma", Font.PLAIN, 12));
		contentPane.add(lblGreeting1);
		
		JButton btnExit = new JButton("\u0418\u0437\u0445\u043E\u0434");
		btnExit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		sl_contentPane.putConstraint(SpringLayout.SOUTH, btnExit, -10, SpringLayout.SOUTH, contentPane);
		sl_contentPane.putConstraint(SpringLayout.EAST, btnExit, -27, SpringLayout.EAST, contentPane);
		contentPane.add(btnExit);
		
		JButton btnReset = new JButton("\u0418\u0437\u0447\u0438\u0441\u0442\u0438");
		btnReset.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				txtName.setText("");
				lblGreeting1.setText("");
				lblGreeting2.setText("");
			}
		});
		sl_contentPane.putConstraint(SpringLayout.EAST, btnReset, -124, SpringLayout.EAST, contentPane);
		sl_contentPane.putConstraint(SpringLayout.WEST, btnExit, 24, SpringLayout.EAST, btnReset);
		sl_contentPane.putConstraint(SpringLayout.SOUTH, btnReset, -10, SpringLayout.SOUTH, contentPane);
		contentPane.add(btnReset);
		

		sl_contentPane.putConstraint(SpringLayout.NORTH, lblGreeting2, 17, SpringLayout.SOUTH, lblGreeting1);
		sl_contentPane.putConstraint(SpringLayout.WEST, lblGreeting2, 0, SpringLayout.WEST, lblName);
		sl_contentPane.putConstraint(SpringLayout.SOUTH, lblGreeting2, -32, SpringLayout.NORTH, btnExit);
		sl_contentPane.putConstraint(SpringLayout.EAST, lblGreeting2, -10, SpringLayout.EAST, contentPane);
		lblGreeting2.setForeground(new Color(204, 102, 51));
		lblGreeting2.setFont(new Font("Tahoma", Font.PLAIN, 12));
		contentPane.add(lblGreeting2);
		
		JButton btnGreeting = new JButton("\u0417\u0430\u043F\u043E\u0437\u043D\u0430\u0439 \u0441\u0435!");
		sl_contentPane.putConstraint(SpringLayout.WEST, btnReset, 24, SpringLayout.EAST, btnGreeting);
		sl_contentPane.putConstraint(SpringLayout.WEST, btnGreeting, 24, SpringLayout.WEST, contentPane);
		sl_contentPane.putConstraint(SpringLayout.SOUTH, btnGreeting, -10, SpringLayout.SOUTH, contentPane);
		btnGreeting.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String name = txtName.getText();
				
				String strGreeting1 = "Здравей, " + name + "!";
				lblGreeting1.setText(strGreeting1);
				
				String strGreeting2 = name + ", Java иска да работи с теб!";
				lblGreeting2.setText(strGreeting2);
			}
		});
		contentPane.add(btnGreeting);
	}
}
