• 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

Help! Function returns bad value when inside .addActionListener

 
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a piece of code that dynamically creates JButtons (jb) while reading data from a prefs file. The prefs file is opened, and the data objects (ButtonData is a custom class that contains information associated with each button) are read in. For each one (two total, in this test case) a JButton is dynamically created.
The problem is that just before jb.addActionListener(), bd.getObjectArray() returns two unique object arrays (as it should), one for each iteration. However, inside the .addActionListener(), bd.getObjectArray() returns the same object array for both iterations!
Does anyone know what might be causing this? I have a feeling the solution is simple, but I can't see it.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic