I'm doing a simple system of registering students and teachers and wanted to interact with a JMenuItem
called exit , the program closed.
I made the whole algorithm, but with that exclamation informing me that my ActionPerformed method is not being used, I do not understand that error follows the code below:
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Janela {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800, 600);
frame.setLocation(400, 300);
JMenuBar barramenu = new JMenuBar();
//Menu Cadastro
JMenu cadastro = new JMenu("cadastro");
JMenuItem professor = new JMenuItem("Professor");
JMenuItem aluno = new JMenuItem("Aluno");
cadastro.add(professor);
cadastro.add(aluno);
//Menu Pesquisa
JMenu pesquisa = new JMenu("Pesquisa");
JMenuItem professor1 = new JMenuItem("Professor");
JMenuItem aluno1 = new JMenuItem("aluno");
pesquisa.add(professor1);
pesquisa.add(aluno1);
//Menu Excluir
JMenu excluir = new JMenu("Excluir");
JMenuItem professor2 = new JMenuItem("Professor");
JMenuItem aluno2 = new JMenuItem("aluno");
excluir.add(professor2);
excluir.add(aluno2);
//Menu sistema
JMenu sistema = new JMenu("Sistema");
JMenuItem sobre = new JMenuItem("Sobre");
JMenuItem sair = new JMenuItem("Sair");
sistema.add(sobre);
sistema.add(sair);
barramenu.add(cadastro);
barramenu.add(pesquisa);
barramenu.add(excluir);
barramenu.add(sistema);
frame.getContentPane().add(barramenu, BorderLayout.NORTH);
frame.setVisible(true);
sair.addActionListener(new ActionListener(){
public void ActionPerformed(ActionEvent e){
System.exit(0);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
});
}
}