import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import javax.swing.border.*;
import java.sql.*;
//import oracle.jdbc.*;

public class Jelszo extends JDialog implements ActionListener{
	
private final String strOK = "OK";
private final String strMegsem = "M\u00e9gsem";
 
private String str2;
private boolean m_succeeded = false;
private JButton okGomb;
private JButton megsemGomb;
private JPanel gombPanel;
private JPanel adatPanel;
private JTextField m_loginNameBox;
private JPasswordField m_passwordBox;
private Menu1 szuloPanel;

private JPanel kontener;

private String m_loginName;
private String m_password;

private int m_errCounter = 0;

public Jelszo(JFrame parent){
	super(parent, "Bejelentkez\u00e9s", true);
	szuloPanel = (Menu1)parent;
	setBounds(355,290,300,130);
	okGomb = new JButton(strOK);
	okGomb.addActionListener(this);
	megsemGomb = new JButton(strMegsem);
	megsemGomb.addActionListener(this);
	
	gombPanel = new JPanel(new FlowLayout( FlowLayout.CENTER));
	gombPanel.add(okGomb);
	gombPanel.add(megsemGomb);
	
	adatPanel = new JPanel(new FlowLayout( FlowLayout.RIGHT));
	adatPanel.setBorder(new EmptyBorder(10,0,0,10));
	
	adatPanel.add(new JLabel("       Felh.n\u00e9v:   "));
	m_loginNameBox = new JTextField("",16);
	adatPanel.add(m_loginNameBox);
	
	adatPanel.add(new JLabel("        Jelsz\u00f3:   "));
	m_passwordBox = new JPasswordField("",16);
	adatPanel.add(m_passwordBox);
	
	kontener = new JPanel(new BorderLayout());
	kontener.add(adatPanel,BorderLayout.CENTER);
	kontener.add(gombPanel,BorderLayout.SOUTH);
	getContentPane().add(kontener);
    setLocationRelativeTo(parent);
	
	
 }
 public void actionPerformed(ActionEvent ae){
 	String str = ae.getActionCommand();
 	if(str.equals(strOK)){
		m_loginName = m_loginNameBox.getText();
		m_password = new String(m_passwordBox.getPassword());
        String driver = "oracle.jdbc.OracleDriver";
        String url    = "jdbc:oracle:thin:@oracle.inf.unideb.hu:1521:oracle";
		
		try
		{
	        Class.forName( driver );
		}
		catch ( ClassNotFoundException e )
		{
		
			JOptionPane.showMessageDialog(this,e.getMessage(),"HIBA",JOptionPane.ERROR_MESSAGE);
			System.exit( 0 );
		}
  	

        try
        {
        	szuloPanel.con = DriverManager.getConnection( url, m_loginName, m_password );
        //	szuloPanel.con = DriverManager.getConnection( url, "kunani", "kunani");
        }
        catch ( SQLException exp )
        {
	
			JOptionPane.showMessageDialog(this,"Hiba!","Hib\u00e1s n\u00e9v vagy jelsz\u00f3!!!",JOptionPane.ERROR_MESSAGE);
        }
    	  szuloPanel.almenu1.setEnabled(false);
    	  szuloPanel.almenu2.setEnabled(true);
    	  szuloPanel.menu3.setEnabled(true);
      	    	 
        	m_succeeded = true;
    
		szuloPanel.removePanel(this);
        JOptionPane.showMessageDialog(this,"Kapcsolat l\u00e9trej\u00f6tt","Inform\u00e1ci\u00f3",JOptionPane.INFORMATION_MESSAGE);
 	}
 	else if(str.equals(strMegsem)){
 		szuloPanel.removePanel(this);
 	}
 }
 public boolean succeeded(){
 	return m_succeeded;
 }
 public String getLoginName(){
 	return m_loginName;	
 }
 public String getPassword(){
 	return m_password;
 }
 
} 