Bonjour à tous,
pour une question d'organisation, je désire séparer le code graphique du reste. Pour cela, j'ai crée un package qui gère les JFrame et un autre package qui gère les Controller.
voici ma classe de controlle:
public class LogController implements ActionListener {
private LogVue logVue;
private Tout tout;
public LogController(LogVue logVue){
this.logVue = logVue;
logVue.getJb_valid().addActionListener(this);
}
public void actionPerformed(ActionEvent act) {
Object src = act.getSource();
// la source est le bouton valider ::
if ( src.equals(logVue.getJb_valid()) ){
tout.setVisible(true);
}
voici la classe LogVue
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
LogVue inst = new LogVue();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}
public LogVue() {
super();
initGUI();
control = new LogController(this);
}
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setLayout(null);
{
jb_valid = new JButton();
getContentPane().add(jb_valid);
jb_valid.setText("Valider");
jb_valid.setBounds(85, 121, 79, 29);
}
public JButton getJb_valid() {
return jb_valid;
}
......}
et voici l'erreur:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Controller.LogController.actionPerformed(LogController.java:39)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
merci d'avance pour votre aide