Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Inner Class

 
Ranch Hand
Posts: 86
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Is the first time where trying to use inner class, so occurring some obstacles. I have an inner class that extends JButton and has getters and setters for X and Y (coord.) . So how and where, can I in my outer class create and initialise an array of inner class?

Thank you
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pan Niko wrote:Hello,

Is the first time where trying to use inner class, so occurring some obstacles. I have an inner class that extends JButton and has getters and setters for X and Y (coord.) . So how and where, can I in my outer class create and initialise an array of inner class?

Thank you



So, what have you tried and what exact problems are you having? Have you googled for java inner class tutorial?
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Inside the outer class, using the inner class is just like using any other class*. So, do you know how to create and initialise an array of a normal class - say, JButton?

(* with a bit of a difference if it's a non-static inner class, and you're in a static method, but let's keep it simple to start with).
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My best guess at this point is that Pan is talking about an anonymous inner class, and is having trouble with the type of the array. But I'd like to hear from Pan exactly what the problem is before offering suggestions. :-)
 
Pan Niko
Ranch Hand
Posts: 86
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok thanks all of you for you response. Tried something like



At first didn't work, re-open eclipse and everything was fine!! Don't know the reason.

Now because I'm working first time with setActionCommand(String); I would like to know, if you have an array of JButton, you should create setActionComman(String); and addActionListener(listener) for each button individually? There is an simpler way?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic