You can in theory run such code anywhere. But why? A frame is intended for displaying things, not for running loops. If you simply run that loop, you will be asking for information much faster than you can write in the fields.
What you might do is add listeners to text fields, or to buttons. I think you can add action listeners which are fired when you push the enter key on a text component. You can have a label where you set the text something like
Enter In Time No 123
adjacent to a text field where you can enter the time. You can use the enter key on the text fields or a button to fire an action.
Have you got the logic for that loop working correctly? Why have you got an empty catch statement? That is dangerous because Exceptions can occur and you would never know. Don't even think about a GUI until you have that loop working correctly.