aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Diff. between Event listener & Event Mask ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Diff. between Event listener & Event Mask ?" Watch "Diff. between Event listener & Event Mask ?" New topic
Author

Diff. between Event listener & Event Mask ?

D_malik
Greenhorn

Joined: Oct 04, 2000
Posts: 4
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

Joined: Sep 22, 2000
Posts: 53
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

Joined: Oct 04, 2000
Posts: 4
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

Joined: Sep 22, 2000
Posts: 53
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Diff. between Event listener & Event Mask ?