Link to home
Start Free TrialLog in
Avatar of Suppai
Suppai

asked on

Best practice for handling events for multiple gui components

What is the best practice way to handle events, when multiple event sources (e.g. multiple buttons) are present in a gui? Should separate listeners be created or only one with a switch defining the source of the event? Or something else?
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Suppai
Suppai

ASKER

Can you provide an example of good design using separate listeners then?
sendButton.addActionListener(new ActionListener()
{
   public void actionPerformed(ActionEvent event)
   {
       send();
   }
});
doSomethingElseButton.addActionListener(new ActionListener()
{
   public void actionPerformed(ActionEvent event)
   {
       doSomethingElse();
   }
});