1

I want to write a time specific actionListener which triggers some action at a specific time. I know that there is ScheduledExecutorService in java which can be used to trigger a action at some specific time but I want to try actionListener.

Let suppose I create a txt file and want to remove it after an hour. How can I do it by actionListener ? any example code ?

2
  • An ActionListener responds to an action - you want to perform an action at some later point in time... ActionListener doesn't have anything directly to do with this (other than perhaps kicking off the process if you're doing it via a button press) Commented Aug 7, 2014 at 13:37
  • exactly ActionListener responds to an action. Triggering a specific time could also be an action. I am not using any swing or awt component like buttons or anything. Commented Aug 7, 2014 at 13:45

1 Answer 1

3

I want to write a time specific actionListener which triggers some action at a specific time. I know that there is ScheduledExecutorService in java which can be used to trigger a action at some specific time but I want to try actionListener.

have look at Swing Timer and event from timer should be invoke Swing Action/ActionListener,

Let suppose I create a txt file and want to remove it after an hour. How can I do it by actionListener ? any example code ?

read Oracles Tutorials for working code examples in MCVE/SSCCE form,

How to use -

Sign up to request clarification or add additional context in comments.

4 Comments

I dont think I need to look for Swing Actions or Swing Timer because I am not using any Swing component. I just want to trigger an action at a specific time (1 hour after file creation).
@JavaDeveloper as Nate told you in his comment, ActionListener responds to an Action (i.e. pressing a button, clicking on a checkbox, combo box, etc). And as I have read on your comment to Nate too, well actionListeners are made for swing, then you don't want an actionListener. Please if you want a better help explain in simple word what you want and provide an example (if posible)
Ok, if ActionListeners are specific for awt components then perhaps I am not going to use it. Its better to use ScheduledExecutorService. Thanks for help and explanation.
not ActionListeners is packaged in awt tree in Java, isn't specifics for AWT Components

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.