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


public class Menu1 extends JFrame implements ActionListener{

	JMenuBar menusor = new JMenuBar();
	JMenu menu1 = new JMenu("Men\u00fc");
	JMenuItem almenu1 = new JMenuItem("Kapcsol\u00f3d\u00e1s");
	JMenuItem almenu2 = new JMenuItem("Kapcsolat bont\u00e1sa");
	JMenuItem almenu3 = new JMenuItem("Kil\u00e9p\u00e9s");
	JMenu menu2 = new JMenu("S\u00fag\u00f3");
	JMenuItem almenu4 = new JMenuItem("Adatok");
	JMenu menu3 = new JMenu("Hallgat\u00f3");
    JMenuItem almenu5 = new JMenuItem("\u00daj hallgat\u00f3 hozz\u00e1ad\u00e1sa");
    JMenuItem almenu6 = new JMenuItem("Teljesit\u00e9sek karbantart\u00e1sa");
    JMenuItem almenu7 = new JMenuItem("Hallgat\u00f3 lista");
    Jelszo jelszoPanel = null;
    Ujhallg hallgatoPanel = null;
    Teljesites teljPanel = null;
    Nevsor nevsorPanel = null;
	String Name;
	String jelszo;
	public Connection con = null;
	

	
    public Menu1(String s) {
    	super(s);
    	setDefaultCloseOperation( EXIT_ON_CLOSE	);
    	setSize(650,500);
    	menu1.add(almenu1).addActionListener(this);
    	menu1.add(almenu2).addActionListener(this);
    	almenu2.setEnabled(false);
    	menu3.add(almenu5).addActionListener(this);
    	menu3.add(almenu6).addActionListener(this);
    	menu3.add(almenu7).addActionListener(this);
    	menu3.setEnabled(false);
    	menu1.addSeparator();
    	menu1.add(almenu3).addActionListener(this);
    	almenu3.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK));
    	
    	menu2.add(almenu4).addActionListener(this);
    	menusor.add(menu1);
    	menusor.add(menu3);
    	menusor.add(Box.createHorizontalGlue());
    	menusor.add(menu2);
    	
   
    	this.setJMenuBar(menusor);
   
    	this.setVisible(true);
    	this.setLocationRelativeTo( null );
    }
    
    public void actionPerformed(ActionEvent e){
    	this.setTitle(e.getActionCommand());
    	if(e.getActionCommand() == "Kil\u00e9p\u00e9s")
    		System.exit(0);
    	else if(e.getActionCommand() == "Kapcsol\u00f3d\u00e1s"){
    		if( jelszoPanel == null)
    			jelszoPanel = new Jelszo(this); 
    		jelszoPanel.setVisible(true);
    		jelszoPanel=null;
    		
    			 
    	}
    	else if(e.getActionCommand() == "Adatok"){
    		Adat a = new Adat("Adatok");
    		a.setVisible(true);
    		a=null;
    	}
    	else if(e.getActionCommand() == "Kapcsolat bont\u00e1sa") {
          	try{
                  int n = JOptionPane.showConfirmDialog(
                            this, "Biztos ki akar l\u00e9pni?",
                            "Kil\u00e9p\u00e9s",
                            JOptionPane.YES_NO_OPTION);
                    if (n == JOptionPane.YES_OPTION) {
                         con.close();
                         JOptionPane.showMessageDialog(this,"Kapcsolat bontva.","Inform\u00e1ci\u00f3",JOptionPane.INFORMATION_MESSAGE);
   
                          almenu1.setEnabled(true);
           	              almenu2.setEnabled(false);
           	              menu3.setEnabled(false);
                    } else if (n == JOptionPane.NO_OPTION) {
                        
                    } 
               
           	    
       	    }
    	    catch(SQLException ex){
    		 
			  JOptionPane.showMessageDialog(this,ex.getMessage(),"HIBA",JOptionPane.ERROR_MESSAGE);
    	    }
    		
    	}
    	else if(e.getActionCommand() == "\u00daj hallgat\u00f3 hozz\u00e1ad\u00e1sa"){
    	    if(hallgatoPanel == null)
    	        hallgatoPanel = new Ujhallg(this);
    		hallgatoPanel.setVisible(true);
    		hallgatoPanel = null;
    	}
        else if(e.getActionCommand().equals("Teljesit\u00e9sek karbantart\u00e1sa")){
        	if(teljPanel == null)
        		teljPanel = new Teljesites(this);
        	teljPanel.setVisible(true);
        	teljPanel = null;
        	
        }
        else if(e.getActionCommand().equals("Hallgat\u00f3 lista")){
		if(nevsorPanel == null)
			    nevsorPanel = new Nevsor(this);
			nevsorPanel.setVisible(true);
			nevsorPanel = null;
				       	
        }
    
    	
    }
    public static void main(String args[]){
    	Menu1 ablak = new Menu1("Men\u00fc kezel\u00e9se");
    }
    
     public void removePanel(JDialog o) {
        if (  o!= null ) {
            o.dispose();
            o = null;
        }
     }
    
}
