Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem with ActionListener firing multiple times

lfdJan 9 2012 — edited Jul 30 2012
I have a GUI class, GUIView, with a no-arg constructor and a static getInstance() method.

The GUI class has a JButton called btnB1 with a method:
	void addB1Listener(ActionListener al){
		btnB1.addActionListener(al);
	}
The Controller class has an instance of the GUI and the Model.
The Controller has a constructor which assigns a new ActionListener to the JButton from the GUI.
private GUI m_gui;
	FTController(GUIView view){
		m_gui = view;
		m_gui.addButtonListener(new AddButtonListener());
	}
The Controller has an inner class:
class AddButtonListener implements ActionListener{
		@Override
		public void actionPerformed(ActionEvent e) {
                      // do stuff
		}
}
The model has a constructor which accepts a GUIView.

My main method setups instances of the objects:
	
	private GUIView view;
	private Model model;
	private Controller controller;

	public static void main(String [] args){
		view = GUIView.getInstance();
		model = new Model(view);
		controller = new Controller(view);
	}
This action listener for btnB1 is firing multiple times, but I don't understand why.

Edited by: user10199598 on Jan 9, 2012 2:56 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 27 2012
Added on Jan 9 2012
29 comments
5,172 views