Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Diff. between Event listener & Event Mask ?

 
D_malik
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got questions regarding Explicit Event Enabling (a alternative to component's event)
Under what conditions this XXX_EVENT_MASK is used,Or we can work only with regular event delgation model without even knowing about it.
Please clear about the above diffrence to make me understand about this topic.
Thanks in advance for reply
D_malik
 
Harry Singh
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its just another way of doing the same thing. There are listeners provided for every event and you could use them.
Option 1:
Button myButton = new Button();
myButton.addActionListener(new ActionListener() {} );
Option 2:
class myButton extends Button {

enableEvents(ACTION_EVENT_MASK);
public void processActionEvent(ActionEvent e) {};
}

Option 3: // which is almost same as option 2
class myButton extends Button {

enableEvents(ACTION_EVENT_MASK);
public void processEvent(AWTEvent e) {
if e.getID() == ACTION_EVENT_MASK };
}

Hope it helps,
Harry
 
D_malik
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Harry
I am not still clear in what condition this processEvent methods are used or it just a another approach to Event model.
Dharam
 
Harry Singh
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dharam,
You are right. Its another way of doing things. It depends on the design. Lets say you are writing a calculator and each button is just supposed to write to the display when it is clicked. You can either create 10 buttons ( 1,2,3 ... ) and add Listeners to them individaully. Instead why not subclass Button, add the ProcessEvent and ENABLE_EVENT code and do it once. I hope it makes sense.
Thanks,
Harry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic