Estou estudando o Pattern MVC, mas estou sofrendo com uma questão de entendimento.
Classe Eventos
[code]
package estudoeventos;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
/**
*
-
@author User
*/
public class Eventos{Gui gui = new Gui();
public Eventos(Gui evento) {
this.gui = evento;
evento.bAcaoaddActionListener(new Evento());
}
class Evento implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "A janela apareceu");
}
}
}[/code]
classe Visao
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package estudoeventos;
import java.awt.event.ActionListener;
/**
*
* @author User
*/
public class Gui extends javax.swing.JFrame {
/**
* Creates new form Gui
*/
public Gui() {
initComponents();
}
//metodo próprio
public void bAcaoaddActionListener(ActionListener evento){
bAcao.addActionListener(evento);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
bAcao = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
bAcao.setText("acao");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(137, 137, 137)
.addComponent(bAcao)
.addContainerGap(208, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(129, 129, 129)
.addComponent(bAcao)
.addContainerGap(148, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/*
* Set the Nimbus look and feel
*/
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/*
* If Nimbus (introduced in Java SE 6) is not available, stay with the
* default look and feel. For details see
* http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/*
* Create and display the form
*/
}
// Variables declaration - do not modify
private javax.swing.JButton bAcao;
// End of variables declaration
}
EstudoEventos
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package estudoeventos;
/**
*
* @author User
*/
public class EstudoEventos {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Gui gui = new Gui();
gui.setVisible(true);
}
}
Gostaria de saber o porquê do bAcao não chamar a ação da classe eventos??? Muito obrigada por suas explicações.