Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

In more details, I have a loop that takes in mathematical operations and a switch case in which it translates those operations in order to apply addition or subtraction.. etc.

The loop (int i) is the number of operations it reads. The condition is also a part of the operations entered, it's also inside the switch case. So whenever the user enters that condition, and the number (for instance j) that the loop should repeat, the program should take in j and equalizes it with i but it freezes. I want it to branch to that part of the loop where the user defines to get the condition right.

the GUI freezes once the user hits a JButton so that operations written in TextArea are to be calculated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
268 views
Welcome To Ask or Share your Answers For Others

1 Answer

the GUI freezes once the user hits a JButton

Code invoked in a listener executes on the Event Dispatch Thread (EDT). The EDT is responsible for handling events and painting the GUI. So if you execute long running tasks when you click on the button you will cause the GUI to freeze until the task finishes executing.

You need to execute the long running task on a separate Thread. One way to do this is to use a Swing Worker. Read the section from the Swing tutorial on Concurrency for more information about the EDT and SwingWorker.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...