Making the user wait using Swing

前端 未结 4 985
梦谈多话
梦谈多话 2021-01-21 05:48

I want to make the user to wait for a certain amount of time (10 seconds). I know in JSP or in servlets we use the META tag

4条回答
  •  清酒与你
    2021-01-21 05:57

    Prior to WebSockets, HTTP servers could not send HTTP clients 'events'; the interactions were basically request-response. Many applications work around this problem using a (client-side) polling approach. The refresh meta-tag is one way of implementing polling.

    Swing is very different -- you have the full strength of events. So the idea of making a user wait for a predetermined amount of time is usually the incorrect interaction. (Some sort of game/quiz/animation are a few of the exceptions, where simply waiting makes sense.)

    You should design a Swing GUI that is functional and responsive while the results haven't been computed/received. Once the results are available, update a model, and fire an event advertising that the model has changed.

    The model itself can do background computation, polling etc as necessary; that code is not swing specific. If you would like help on that aspect, consider looking for/asking about that separately on Stack Overflow.

    Finally, remember that sleeping on the swing thread will make the UI unresponsive. And on a related note, any event fired by your model should be queued onto the Swing event thread. See SwingUtilities.invokeLater(...) about how that is done.

提交回复
热议问题