package klient;

import javax.swing.*;
import java.awt.event.*;
/**
 * @author w21826 Piotr Lezon 8MKDR-TI-SZL
 *
 */

public class Opcje extends JFrame implements ActionListener
{
	JTextField serwer;
	JTextField port;
	JTextField nickname;
	JButton ok;
	
	public Opcje()
	{
		this.setTitle("Opcje polaczenia");
		this.setLayout(null);
		this.setSize(300,250);
		this.setVisible(true);
		JLabel Serwer=new JLabel("Adres serwera: ");
		Serwer.setSize(100,20);
		Serwer.setLocation(20, 10);
		this.add(Serwer);
		serwer=new JTextField();
		serwer.setSize(100,20);
		this.add(serwer);
		serwer.setLocation(120,10);
		JLabel Port=new JLabel("Port: ");
		Port.setSize(100,20);
		Port.setLocation(20, 40);
		this.add(Port);
		port=new JTextField();
		port.setSize(100,20);
		port.setLocation(120, 40);
		this.add(port);
		JLabel Nick=new JLabel("Nick: ");
		Nick.setSize(100,20);
		Nick.setLocation(20,70);
		this.add(Nick);
		nickname=new JTextField();
		nickname.setSize(100,20);
		nickname.setLocation(120,70);
		this.add(nickname);
		ok=new JButton("OK");
		ok.setSize(100,20);
		ok.setLocation(75,100);
		this.add(ok);
		ok.addActionListener(this);
	}
	

	public void actionPerformed(ActionEvent e)
	{

		if(e.getActionCommand() == "OK") 
		{
			if(serwer.getText().compareTo("") != 0 && port.getText().compareTo("") != 0 && nickname.getText().compareTo("") != 0)
			{
				Klient.serwer=serwer.getText();
				Klient.port=Integer.valueOf(port.getText());
				Klient.nick=nickname.getText();
				this.dispose();
			}
			else
			{
				JOptionPane.showMessageDialog(this, "Nie podales wymaganych danych!", "Blad!", JOptionPane.ERROR_MESSAGE);
		
			}
		}
	}

}
