import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class JavaPasswordArayuzu {

	public JavaPasswordArayuzu() {
		
		Font userFont = new Font("Ubuntu", Font.PLAIN, 17); // fonts.google.com
		
		JFrame frame = new JFrame("JPasswordField Giriş Ekranı | Java Blackboard [123]");
		frame.setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setLayout(null);
		panel.setBackground(new Color( 224, 237, 253));
		panel.setBounds(50, 50, 500, 300);
		
		JLabel userLabel = new JLabel("User : ");
		userLabel.setFont(userFont);
		userLabel.setHorizontalAlignment(JLabel.RIGHT);
		userLabel.setBounds(30, 30, 100, 30);
		
		JTextField userTF = new JTextField();
		userTF.setBounds(150, 30, 200, 30);
		
		JLabel userPass = new JLabel("Password : ");
		userPass.setFont(userFont);
		userPass.setHorizontalAlignment(JLabel.RIGHT);
		userPass.setBounds(30, 70, 100, 30);
		
		JLabel labelOnay = new JLabel("");
		labelOnay.setFont(userFont);
		labelOnay.setBounds(150, 200, 200, 30);
		
	//	char pwc = '\u265F'; // SiyahPiyon : '\u265F'
	//	char pwc = '\u265B'; // SiyahVezir : '\u265B'
		char pwc = '\u2605'; // SiyahYildiz
		
		JPasswordField userPF = new JPasswordField();
		userPF.setEchoChar(pwc); // 
	//	userPF.setEchoChar('♕'); // SiyahVezir
	//	userPF.setEchoChar('♟'); // SiyahPiyon
	//	userPF.setEchoChar((char)0); // Sifrenin gorunmesini saglar.
	//	userPF.setEchoChar((char)1); // Sifrenin tam gizliligini saglar. Imleç hareket etmez.
	//	userPF.setEchoChar((char)2); // Sifrenin imleç hareketini gösterir...
	//	userPF.setEchoChar((char)-1); // Sifrenin bos kare seklinde gorunmesini saglar
		
		userPF.setBounds(150, 70, 200, 30);
		
		JButton loginButon = new JButton("Login");
		loginButon.setBounds(150, 110, 200, 30);
		
		loginButon.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
			//  Sifreyi bu sekilde ALMAYINIZ!!!
			//	String parola = userPF.getText();
				
				char[] passKarakterDizisi = userPF.getPassword();
				String parola = new String(passKarakterDizisi);
				
				String userName = userTF.getText(); 
				
				if (userName.equals("istanbul") && parola.equals("1453")) {
					
					labelOnay.setForeground(new Color(4, 156, 21)); // Yesil
					labelOnay.setText("Giriş Onaylandi.");
					
				} else {
					
					labelOnay.setForeground(new Color(255, 0 ,0)); // Kirmizi
					labelOnay.setText("Giriş Reddedildi.");
					
				}
			}
		});

		panel.add(userLabel);
		panel.add(userTF);
		
		panel.add(userPass);
		panel.add(userPF);
		
		panel.add(loginButon);
		
		panel.add(labelOnay);
		
		frame.add(panel);
		
		frame.setSize(600, 425);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setResizable(false);
        frame.setVisible(true);
	}

	public static void main(String[] args) {

		new JavaPasswordArayuzu();
		
	}

}
