Boa tarde pessoal,
Estou com um problema ao tratar de evento de botão.
Tenho duas classes em pacotes diferentes…
Uma que tem os 2 botões que eu quero tratar, e a outra classe que trata o evento…
Na classe que tem os botões eu fiz o seguinte:
JButton bCont = new JButton("Contatos");
JButton bComp = new JButton("Compromissos");
bCont.addActionListener(new AberturaControle(this));
bComp.addActionListener(new AberturaControle(this));
Na classe que trata o evento, implementei o ActionListener e fiz o seguinte:
public void actionPerformed(ActionEvent e) {
Object ob = e.getSource();
if(ob == bComp){
new CompromissosVisao();
}
if(ob == bCont){
new ContatosVisao();
}
Importei as classes e tudo… Mas não deu certo…
Ao tentar rodar o programa, se eu clico em um dos botões aparece o seguinte erro:
[b][color=red] Exception in thread “AWT-EventQueue-0” java.lang.Error: Unresolved compilation problems:
bComp cannot be resolved
bCont cannot be resolved
at controle.AberturaControle.actionPerformed(AberturaControle.java:19)
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)
[/b][/color]
Alguém pode me ajudar?
Agradeço desde já,
Dina