As a general rule, I like anonymous classes, provided you only use them once each. I do not like addActionListener(this), because it often denotes failure to use proper object design.Tony Docherty wrote: . . .This is a good place to use an anonymous inner class . . .
Campbell Ritchie wrote:I do not like addActionListener(this), because it often denotes failure to use proper object design.
Tony Docherty wrote:I thought you wanted to wait 2 seconds and not 50 milliseconds!
You need to pass an ActionListener into the Timer's constructor.
You are passing 'this' which means when the timer completes it will call this objects actionPerformed method which creates and starts a new timer again and so on and so on.
BTW This is a good place to use an anonymous inner class ie
By default Timers repeat every n milliseconds so before starting it you should call
And if that isn’t non‑object‑oriented design, I don’t know what is!Tony Docherty wrote: . . . when the actionPerformed method has a list of if-else statements . . .
Campbell Ritchie wrote:And what goes wrong? We can’t help without more details.
Michael Dunn wrote:> Can you explain me why have you made String originalText as final....
remove the word 'final', recompile, see what happens.