wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Netbeans ActionListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Netbeans ActionListener" Watch "Netbeans ActionListener" New topic
Author

Netbeans ActionListener

Rob Brew
Ranch Hand

Joined: Jun 23, 2011
Posts: 99
I'm using this guide to creating java GUI classes using MVC, I'm on NetBeans.

NetBeans creates to code

However it won't compile as ActionListener was required and we're hard coded with ActionEvent.

Netbeans won't let me reformat the method code. I know ik could cut and paste it into another editor but there must be a way to keep with NetBeans?

Thanks,
Rob.
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

ActionListeners' listen for ActionEvents, so you have to set the ActionListener outside of the actionPerformed() method, otherwise the method will never be called.

Have a look at the Java tutorial for creating ActionListeners': http://download.oracle.com/javase/tutorial/uiswing/events/actionlistener.html

Hunter


"If the facts don't fit the theory, get new facts" --Albert Einstein
Rob Brew
Ranch Hand

Joined: Jun 23, 2011
Posts: 99
I was going to call the function from the controller class as is done in the MVC model referenced.
Federico Cardelle
Greenhorn

Joined: Jul 26, 2011
Posts: 26
Rob Brew wrote:I was going to call the function from the controller class as is done in the MVC model referenced.


You can call a method in the controller from the actionPerformed...

Rob Brew
Ranch Hand

Joined: Jun 23, 2011
Posts: 99
i was going to do it the other way round, Controller contains objects GUI and methods then invokes the method from there.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38818
    
  23
Does NetBeans really give you a method which adds an ActionListener when you click a button ?
Kristian Aaslund
Greenhorn

Joined: Jul 21, 2011
Posts: 8
Campbell Ritchie wrote:Does NetBeans really give you a method which adds an ActionListener when you click a button ?


No. That line must have been added manually, and has nothing to do there
Rob Brew
Ranch Hand

Joined: Jun 23, 2011
Posts: 99
So how do i add a method which adds an action listener to the GUI and is called by the controller class, passing a class from the controller as an argument?

edit: using netbeans?
Rob Brew
Ranch Hand

Joined: Jun 23, 2011
Posts: 99
Ok I know that NetBeans provides a method which is invoked when an action listener is added to the form, what i'm trying to do is use MVC, make a controller class which accepts a GUI and a business logic class, and invokes methods on the GUI passing it's own class as an argument to be performed, as in this guide.

Any ideas folks?

Thanks,
Rob.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Netbeans ActionListener