aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes when to use ActionListener interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "when to use ActionListener interface" Watch "when to use ActionListener interface" New topic
Author

when to use ActionListener interface

abhay jain
Ranch Hand

Joined: Jun 03, 2011
Posts: 130
when to use ActionListener interface in a program , i am confused after watching to many interfaces , please help
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10535
    
    9

You should use ActionListener when
1) You got components which are capable of triggering action events
2) You are interested in receiving such events

e.g. JButton is capable of triggering action event (since it has the addActionListener() method) If you want to get notified when a particular button is pressed you would use an action listener


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
abhay jain
Ranch Hand

Joined: Jun 03, 2011
Posts: 130
Thanks maneesh

can we also use MouseListener (in case of JButton and mouse event on it ) in place of ActionListener
if yes then what will be pros and cons of it
if no then please tell me ....why ?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4490
    
    8

You can use a MouseListener if you're interested in responding to mouse events. Usually you don't want that on a JButton, because "pressing" a button is more complicated than just clicking on it. For instance, you can activate it using the keyboard.
abhay jain
Ranch Hand

Joined: Jun 03, 2011
Posts: 130
Thanks a lot Matthew
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40034
    
  28
Look at this section in the Java™ Tutorials.

This looks like a Swing/AWT related question, so I shall move this discussion to our GUIs forum.
abhay jain
Ranch Hand

Joined: Jun 03, 2011
Posts: 130
Great ....... thanks a lot Campbell Ritchie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: when to use ActionListener interface