Java Swing - GUI freezes when completing calculations after clicking a button

后端 未结 3 1109
予麋鹿
予麋鹿 2021-01-25 07:17

I have created a scientific calculator program. What my program does is take \"label\" which is the string inputted by the user using buttons and evaluate the expression. What m

3条回答
  •  有刺的猬
    2021-01-25 07:55

    The solution is to:

    1. Use a separate Thread and use SwingUtilities.inovkeLater() to place the text field updates on the EDT, or

    2. Use a SwingWorker, which has a built in API to support the above to features.

    Read the section from the Swing tutorial on Concurrency in Swing for complete information and working examples of a SwingWorker.

提交回复
热议问题