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

后端 未结 3 1122
予麋鹿
予麋鹿 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 08:04

    In the method where you call the calculations method, wrap the call in this:

        public void actionPerformed(ActionEvent e){      
        Thread t = new Thread(new Runnable() {
            public void run() {
                try {
                    label2.setText(bracket(splitLabel(label.getText())));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        t.start();
        }
    

    this should solve the problem of the program freezing. if not pleasetell me

提交回复
热议问题