package edu.school;

import java.awt.EventQueue;

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

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

	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JTextField txtProduction;
	private JTextField txtAuthor;
	private JTextField txtActor1;
	private JTextField txtActor2;
	private JTextField txtActor3;
	private JTextField txtRole1;
	private JTextField txtRole2;
	private JTextField txtRole3;

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

	/**
	 * Create the frame.
	 */
	public TheatreFrame() {
		setTitle("\u0422\u0435\u0430\u0442\u044A\u0440");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 366, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblProduction = new JLabel("\u041F\u043E\u0441\u0442\u0430\u043D\u043E\u0432\u043A\u0430:");
		lblProduction.setForeground(new Color(0, 51, 51));
		lblProduction.setFont(new Font("Tahoma", Font.BOLD, 12));
		lblProduction.setBounds(10, 11, 85, 17);
		contentPane.add(lblProduction);
		
		txtProduction = new JTextField();
		txtProduction.setForeground(new Color(0, 51, 51));
		txtProduction.setFont(new Font("Tahoma", Font.PLAIN, 12));
		txtProduction.setBounds(118, 8, 214, 20);
		contentPane.add(txtProduction);
		txtProduction.setColumns(10);
		
		JLabel lblAuthor = new JLabel("\u0410\u0432\u0442\u043E\u0440:");
		lblAuthor.setForeground(new Color(0, 51, 51));
		lblAuthor.setFont(new Font("Tahoma", Font.BOLD, 12));
		lblAuthor.setBounds(10, 42, 85, 17);
		contentPane.add(lblAuthor);
		
		txtAuthor = new JTextField();
		txtAuthor.setForeground(new Color(0, 51, 51));
		txtAuthor.setFont(new Font("Tahoma", Font.PLAIN, 12));
		txtAuthor.setColumns(10);
		txtAuthor.setBounds(118, 39, 214, 20);
		contentPane.add(txtAuthor);
		
		JLabel lblActor = new JLabel("\u0410\u043A\u0442\u044C\u043E\u0440:");
		lblActor.setForeground(new Color(0, 51, 51));
		lblActor.setFont(new Font("Tahoma", Font.BOLD, 12));
		lblActor.setBounds(10, 81, 148, 17);
		contentPane.add(lblActor);
		
		JLabel lblRole = new JLabel("\u0420\u043E\u043B\u044F:");
		lblRole.setForeground(new Color(0, 51, 51));
		lblRole.setFont(new Font("Tahoma", Font.BOLD, 12));
		lblRole.setBounds(184, 83, 148, 17);
		contentPane.add(lblRole);
		
		txtActor1 = new JTextField();
		txtActor1.setForeground(new Color(0, 51, 51));
		txtActor1.setFont(new Font("Tahoma", Font.PLAIN, 12));
		txtActor1.setColumns(10);
		txtActor1.setBounds(10, 109, 148, 20);
		contentPane.add(txtActor1);
		
		txtActor2 = new JTextField();
		txtActor2.setForeground(new Color(0, 51, 51));
		txtActor2.setFont(new Font("Tahoma", Font.PLAIN, 12));
		txtActor2.setColumns(10);
		txtActor2.setBounds(10, 143, 148, 20);
		contentPane.add(txtActor2);
		
		txtActor3 = new JTextField();
		txtActor3.setForeground(new Color(0, 51, 51));
		txtActor3.setFont(new Font("Tahoma", Font.PLAIN, 12));
		txtActor3.setColumns(10);
		txtActor3.setBounds(10, 177, 148, 20);
		contentPane.add(txtActor3);
		
		txtRole1 = new JTextField();
		txtRole1.setForeground(new Color(0, 51, 51));
		txtRole1.setFont(new Font("Tahoma", Font.PLAIN, 12));
		txtRole1.setColumns(10);
		txtRole1.setBounds(184, 109, 148, 20);
		contentPane.add(txtRole1);
		
		txtRole2 = new JTextField();
		txtRole2.setForeground(new Color(0, 51, 51));
		txtRole2.setFont(new Font("Tahoma", Font.PLAIN, 12));
		txtRole2.setColumns(10);
		txtRole2.setBounds(184, 143, 148, 20);
		contentPane.add(txtRole2);
		
		txtRole3 = new JTextField();
		txtRole3.setForeground(new Color(0, 51, 51));
		txtRole3.setFont(new Font("Tahoma", Font.PLAIN, 12));
		txtRole3.setColumns(10);
		txtRole3.setBounds(184, 177, 148, 20);
		contentPane.add(txtRole3);
		
		JButton btnInput = new JButton("\u0412\u044A\u0432\u0435\u0434\u0438");
		btnInput.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String production = txtProduction.getText();
				String author = txtAuthor.getText();
				String message = "Очаквайте скоро \n\"" + production + "\" на\n" 
								+ author + "!\n\n";
				message += "Звездите на сцената са:\n\n";
							
				final String ACTOR = "Актьор";
				final String ROLE = "Роля";
				message += String.format("%-20s %-20s\n", ACTOR, ROLE);
				
				String actor;
				String role;
				actor = txtActor1.getText();
				role = txtRole1.getText();
				message += String.format("%-20s %-20s\n", actor, role);
				actor = txtActor2.getText();
				role = txtRole2.getText();
				message += String.format("%-20s %-20s\n", actor, role);
				actor = txtActor3.getText();
				role = txtRole3.getText();
				message += String.format("%-20s %-20s\n", actor, role);
				
				JOptionPane.showMessageDialog(null, message);
			}
		});
		btnInput.setBounds(20, 227, 89, 23);
		contentPane.add(btnInput);
		
		JButton btnReset = new JButton("\u0418\u0437\u0447\u0438\u0441\u0442\u0438");
		btnReset.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				txtProduction.setText("");
				txtAuthor.setText("");
				txtActor1.setText("");
				txtActor2.setText("");
				txtActor3.setText("");
				txtRole1.setText("");
				txtRole2.setText("");
				txtRole3.setText("");
			}
		});
		btnReset.setBounds(129, 227, 89, 23);
		contentPane.add(btnReset);
		
		JButton btnExit = new JButton("\u0418\u0437\u0445\u043E\u0434");
		btnExit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		btnExit.setBounds(238, 227, 89, 23);
		contentPane.add(btnExit);
	}
}
