• Post Reply Bookmark Topic Watch Topic
  • New Topic

Inner Class  RSS feed

 
Pan Niko
Ranch Hand
Posts: 86
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • 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
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • 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?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!