• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Netbeans ActionListener

 
Rob Brew
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Brew
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was going to call the function from the controller class as is done in the MVC model referenced.
 
Federico Cardelle
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does NetBeans really give you a method which adds an ActionListener when you click a button ?
 
Kristian Aaslund
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic