[b]Olá amigos. Estou com problemas no JOptionPane, em que ao executar o código, não aparece erro algum, mas também as mensagens que quero fazer aparecer não são exibidas. Fiz vários testes mas não consigo descobrir o erro. Alguém, poderia me auxiliar, por favor?
Vejam o código (dividi o código em várias classes):
[code]import javax.swing.;
import java.awt.;
import java.awt.event.*;
public class CadastroAluno extends JFrame{
private JButton b1, b2;
private JLabel l1, l2, l3, l4, l5, l6, l7, l8, l9;
private JTextField c1, c2, c3, c4, c5, c6, c7, c8, c9;
private TratarCadast tc;
private JPanel p1, p2;
public CadastroAluno() {
setTitle("CADASTRAR ALUNO");
p1 = new JPanel();
p2 = new JPanel();
p1.setLayout(new GridLayout(0,2,4,3));
p2.setLayout(new GridLayout(4,3,8,6));
l1 = new JLabel("NOME");
l2 = new JLabel("ENDEREÇO");
l3 = new JLabel("BAIRRO");
l4 = new JLabel("CEP");
l5 = new JLabel("CIDADE");
l6 = new JLabel("TELEFONE");
l7 = new JLabel("PROFISSÃO");
l8 = new JLabel("MODALIDADE FÍSICA");
l9 = new JLabel("HORÁRIO");
c1 = new JTextField(15);
c2 = new JTextField(15);
c3 = new JTextField(15);
c4 = new JTextField(15);
c5 = new JTextField(15);
c6 = new JTextField(15);
c7 = new JTextField(15);
c8 = new JTextField(15);
c9 = new JTextField(15);
p1.add(l1);
p1.add(c1);
p1.add(l2);
p1.add(c2);
p1.add(l3);
p1.add(c3);
p1.add(l4);
p1.add(c4);
p1.add(l5);
p1.add(c5);
p1.add(l6);
p1.add(c6);
p1.add(l7);
p1.add(c7);
p1.add(l8);
p1.add(c8);
p1.add(l9);
p1.add(c9);
tc = new TratarCadast(b1,b2);
b1 = new JButton("CADASTRO");
b2 = new JButton("EXCLUIR");
b1.setForeground(Color.blue);
b2.setForeground(Color.red);
b1.addActionListener(tc);
b2.addActionListener(tc);
p2.add(b1);
p2.add(b2);
add(p1);
add(p2);
setLayout(new GridLayout(2,0));
setLocation(425,100);
setSize(500, 500);
}
}[/code]
[code]import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;
public class TratarCadast implements ActionListener{
public TratarCadast(){}
private JButton b1, b2;
public TratarCadast(JButton ba, JButton bb){
b1 = ba;
b2 = bb;
}
public void actionPerformed(ActionEvent acao){
if(acao.getSource() == b1) {
JOptionPane.showMessageDialog(null,"OK, CADASTRADO COM SUCESSO");
} else {
if(acao.getSource() == b2) {
JOptionPane.showMessageDialog(null,"OK, EXCLUÍDO COM SUCESSO");
}
}
}
} [/code]