I think you miss understand how GUI's work. Unlike console applications, they don't run in a linear fashion, they are generally event driven.
The clicks or types something, a series of events are raised and you respond to them.
In you ButtonListener
, you respond to the btnReverseString
event by updating the UI and checking to see if the clicked
source is equal to the button you just created and added...this isn't going to work for two reasons.
The first is, each time actionPerformed
you create a new instance of btnConfirm1
, meaning that clicked
and btnConfirm1
could never be equal and two, the user has can't have clicked both btnReverseString
AND btnConfirm1
.
Start by taking a look at Creating a GUI with Swing and How to make dialogs, which will allow you to ask questions of the user inline to your running code (which is what it seems you are trying to do ;))