Results 1 to 1 of 1
  1. #1
    Bruno Xavier is offline Member
    Join Date
    Jan 2013
    Posts
    1
    Rep Power
    0

    Default How to call GUIs maide in netBean by JFrame Form from Main menu using JMenuItem?

    I have this program (Main Menu )
    and I need to call GUIs made in netBean (JFrame Form )
    I need to call them using JMenuItem as you can see in this my program.
    Each char will call a GUI class name.
    You can see that I'v tryed by two times only work one.

    Please help!


    Bruno Xavier


    Quelimane 8/1/2013



    Java Code:
    import java.awt.*;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.KeyStroke;
    import javax.swing.event.MenuKeyEvent;
    import javax.swing.event.MenuKeyListener;
    import javax.swing.event.MenuListener;
    
    
    public class Principal extends JFrame implements ActionListener {
        
        Principal() {
           
            JFrame Janela = new JFrame ("Menu Principal");
            final JPanel panel = new JPanel();
            // final JPanel panel2 = new JPanel();
            
            Janela.add(panel);
            //Janela.add(panel2);
            // Container Janela2 = getContentPane();
           // Janela2.add(panel);
             
            Janela.setResizable(true);
            
      Janela.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 
      JMenuBar barra = new JMenuBar();
      
      JMenu ficheiro = new JMenu ("Ficheiro");
      ficheiro.setMnemonic(KeyEvent.VK_F);
      JMenuItem abrir = new JMenuItem ("Abrir");
      abrir.setMnemonic(KeyEvent.VK_A);
      JMenuItem fechar = new JMenuItem ("Fechar");
      fechar.setMnemonic(KeyEvent.VK_F);
      JMenuItem gravar = new JMenuItem ("Gravar");
      gravar.setMnemonic(KeyEvent.VK_G);
      JMenuItem sair   = new JMenuItem ("Sair");
      sair.setMnemonic(KeyEvent.VK_S);
      
      ficheiro.add(abrir);
      ficheiro.add(fechar);
      ficheiro.add(gravar);
      ficheiro.addSeparator();
      ficheiro.add(sair);
      
      barra.add (ficheiro);
      
      //JMenu opcoes = new JMenu ("OPções");
     // opcoes.setMnemonic(KeyEvent.VK_O);
      JMenu a = new JMenu ("TABELAS");
      a.setMnemonic(KeyEvent.VK_B);
      JMenuItem b = new JMenuItem ("Alunos");
      b.setMnemonic(KeyEvent.VK_A);
      JMenuItem c = new JMenuItem ("Aproveitamento");
      c.setMnemonic(KeyEvent.VK_P);
      JMenuItem d = new JMenuItem ("Ano_Matrícula");
      d.setMnemonic(KeyEvent.VK_M);
      JMenuItem e = new JMenuItem ("Disciplinas");
      e.setMnemonic(KeyEvent.VK_D);
      JMenuItem f = new JMenuItem ("Classes");
      f.setMnemonic(KeyEvent.VK_C);
      JMenuItem g = new JMenuItem ("Exame");
      g.setMnemonic(KeyEvent.VK_E);
      JMenuItem h = new JMenuItem ("Média_Frequência");
      h.setMnemonic(KeyEvent.VK_F);
      JMenuItem i = new JMenuItem ("Resultado_Anual");
      i.setMnemonic(KeyEvent.VK_R);
      JMenuItem j = new JMenuItem ("Resultado_Final");
      j.setMnemonic(KeyEvent.VK_I);
      JMenuItem k = new JMenuItem ("Triméstre");
      k.setMnemonic(KeyEvent.VK_T);
      
      
      a.add(b);
      a.add(c);
      a.add(d);
      a.add(e);
      a.add(f);
      a.add(g);
      a.add(h);
      a.add(i);
      a.add(j);
      a.add(k);
      
      //^opcoes.add(a);
      
      barra.add(a);
      
     JMenu ajuda = new JMenu("Ajuda");
     JMenu tema = new JMenu ("Tema");
     
     JMenuItem aa = new JMenuItem ("Cálculo de Média Anual");
     JMenuItem ab = new JMenuItem ("Cálculo de Média de Frequência");
     JMenuItem ac = new JMenuItem ("Cálculo de Média Final");
     JMenuItem ad = new JMenuItem ("Nota do Exame");
     JMenuItem ae = new JMenuItem ("Comportamento");
     JMenuItem af = new JMenuItem ("Faltas de Presença");
     JMenuItem ag = new JMenuItem ("Fraude Acad]emico");
     
     tema.add(aa);
     tema.add(ab);
     tema.add(ac);
     tema.add(ad);
     tema.add(ae);
     tema.add(af);
     tema.add(ag);
     
     
     ajuda.add(tema);
     barra.add(ajuda);
     //panel2.add(barra);
     abrir.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           escolaEduardoJPanel escola = new escolaEduardoJPanel();
          
          
         panel.add(escola);
           escola.setVisible(true);
           
                }
     });
     fechar.addActionListener(this);
     gravar.addActionListener(this);
     sair.addActionListener(this);
     
     b.addActionListener(new ActionListener() {
       public void actionPerformed(ActionEvent ev) {
           AlunoJFrame aluno = new AlunoJFrame();
           panel.add(aluno);
           //aluno.setResizable(true);
           aluno.setVisible(true);
       }
     });
     c.addActionListener(this);
     d.addActionListener(this);
     
      e.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           DisciplinasFrame disciplina = new DisciplinasFrame();
          
           panel.add(disciplina);
           disciplina.setVisible(true);
           
                }
     });
       f.addActionListener(this);
       g.addActionListener(this);
       h.addActionListener(this);
       i.addActionListener(this);
       j.addActionListener(this);
       k.addActionListener(this);
            
     tema.addActionListener(this);
     
     Janela.setJMenuBar(barra);
     Janela.setVisible(true);
    Janela.setSize(400, 500);
     
        }
     public void actionPerformed (ActionEvent e) {
         String comString = e.getActionCommand();
         System.out.println(comString + " Seleccionado");
     }   
     
      public static void main (String args[]) {
          new Principal();
           
           
      }
    }
    Last edited by JosAH; 01-09-2013 at 09:14 PM. Reason: added [code] ... [/code] tags

Similar Threads

  1. Netbeans jpanel form add jframe form
    By modo91 in forum NetBeans
    Replies: 6
    Last Post: 09-10-2012, 07:08 AM
  2. Creating a Main Menu - Importing
    By l3eater in forum Java Applets
    Replies: 2
    Last Post: 12-28-2010, 05:41 AM
  3. opening a Jframe form in a top of a new form
    By Nubkadiya in forum New To Java
    Replies: 7
    Last Post: 06-01-2010, 08:21 PM
  4. JFrame and JMenuItem
    By Kligham in forum AWT / Swing
    Replies: 10
    Last Post: 01-08-2010, 02:58 AM
  5. Help making a main menu.
    By pbd2 in forum Java Applets
    Replies: 2
    Last Post: 10-17-2008, 10:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •