Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Issue with an javax.swing.Action class and encapsulation/OO design.  RSS feed

 
Daniel Dalton
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone - I've created a stand-alone class which extends javax.swing.AbstractAction, whose purpose is to allow a user to choose a file.
In the actionPerformed() method, having chosen a file, I want to set the value of a JTextField to the filename selected.

The reason why I've created a stand-alone action class rather than as an inner class of another object, is that I want to re-use this functionality in a couple of places. In particular, I have an abstract class, with three concrete classes extending it, two of which need to use this Action class. How do I make the Action class set the JTtextField in the two classes - given that they are private?

I could make the textfield accessible via getter/setter methods in some appropriate fashion, but what I really want to know is whether I'm missing something, and whether Swing has a clever callback type thing that I've completely overlooked.

Any help much appreciated.
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Daniel Dalton
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Craig - that's exactly what I was looking for - couldn't see the wood for the Trees!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!