我有一个带有以下按钮的GUI。当按下它时,应该运行一个新线程(我有一个实现Runnable的类)。但是,当我这样做时,GUI冻结了。我在做什么错,我该如何解决?
//button
addKitchenStaff.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
//create object of a class which implements runnable
KitchenStaff kitchenStaff = new KitchenStaff(allDishes, ingredientsModel, dishesModel,communication.getBap());
//arraylist of all such objects
allKitchenStaff.add(kitchenStaff);
Thread thread = new Thread(kitchenStaff);
thread.run();
}
});
最佳答案
要运行线程,应调用start()
方法。
尝试使用thread.start()
代替thread.run()