简体   繁体   中英

perform task at a user defined time

I need to get a time from the user and schedule my task at that particular time. For getting the time from the user, I displayed the current system time in a JTextField so that the user can edit it easily if wanted.

private JTextField time;    
String date = new SimpleDateFormat("hh:mm:ss").format(new Date());
            time = new JTextField(date);
            time.setBounds(452, 251, 200, 20);
            frame.getContentPane().add(time);
            time.setColumns(10);

But if i do this, I am unable to extract the modified time back in my code. If I extract it by using time.getText() it is in the string format. and i cannot use it in my scheduler

Is there any other way of getting a user defined time in the date format itself?

Also, what is the proper way of delaying my task till the specified time? Its a one-time task, not a repetitive task.

Use a SpinnerDateModel in a JSpinner .

微调器演示

For more information see How to Use Spinners .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM