• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Netbeans ActionListener

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was going to call the function from the controller class as is done in the MVC model referenced.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does NetBeans really give you a method which adds an ActionListener when you click a button ?
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
That's my roommate. He's kinda weird, but he always pays his half of the rent. And he gave me this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic