I have created a button 'Start Search' and when you click on it, a Binary Search Tree is displayed.
However, I would also like this button to then change to 'New Search' - I have done this by just changing its label text when the button is clicked.
Now I want to set it up so that if 'New Search' button is clicked it generates a new tree but I don't know how to tell the actionPerformed method that this button is being clicked a second time(or as the New search button) so now do a different set of instructions.
Am I approaching this wrong? Should I actually create a brand new button once the 'new search' button is clicked and place it in the same area, then I can call the 'new search' button.
Hope someone can help me with where to go with this.
I do not see the difference in the described actions to be performed the first and the second time.
Anyway - resist the temptation to write a boolean hasRun and to use an if-else. Instead use a state pattern: Make two different Actions (different in state or runtime class) and set the second action after the first actionPerformed (e. g. as the last instruction in actionPerformed).
You can set a counter so that when the Star Search is clicked the counter is increased by say one then when the New Search is clicked the counter is reset. Hope that it solves
posted 15 years ago
Thanks very much for the replies. I will look into those and see if I can get it working - will be back if I can't !
The difference for the buttons is a tree is generated as soon as the applet is started, when they 'start search' button is selected - the tree is displayed. Once it is on display the button changes to 'New Search' - I then need to be able to call the methods for generating a new tree and then displaying it so the second call to the button does a little bit more. Hope that my question makes a bit more sense now - sorry i didn't explain it properly the first time round.
Cheers [ August 06, 2005: Message edited by: son dunckley ]