Reputation: 37
So I don't know if it is possible but I was wondering if a button in Java AWT or Swing could be used more than once? Bear with me because I am new to programming.
So I wanted this Choice box that presents the user with options.They select one and press the button continue.
Then the items of the choice are changed and I say b=new Button("");
or b.setText("")
and change the Button
description and use it again for another function. I wish to read using ActionListener
.
Upvotes: 1
Views: 838
Reputation: 140427
You strive to write simple code. One aspect of simplicity: any component, class, object should be responsible for one thing (see SRP).
In your case: GUI elements typically do one job. In general, you do not reuse components like buttons.
Sure, what can make sense:
But you should really not think about reusing individual button objects. Because that means that your button "logic" (that ActionListener) will need to know what "state" the overall application is currently into. And that is more of an anti-pattern.
Upvotes: 2