我的JButton ActionListener有问题.我有一个在另一个类中定义的doTheCleaning()方法,在调用时会对我的GUI进行一系列更改.
public void doTheCleaning(){
//change image icon
//had thread.sleep here
//insert to text area
//had thread.sleep here
//etc
}
Run Code Online (Sandbox Code Playgroud)
然后在另一个类,我实例包含我doTheCleaning()方法的类和有我的ActionListener与我的JButton这样写我的actionPerformed()方法写的:
public void actionPerformed(ActionEvent e){
//some code
//newClass.doTheCleaning();
}
Run Code Online (Sandbox Code Playgroud)
我知道如何像addActionListener()和东西那样做其余的事情,所以不需要对此提出质疑.我担心的是,调用doTheCleaning()方法时执行的GUI中的所有更改仅在单击按钮后才适用.发生这种情况时,我的标签和textarea中发生的更改之间的连续性未显示.如果我直接在我的测试器类中调用它,但在actionperformed方法中调用它只显示我的GUI的最终状态,代码工作正常.我需要先显示哪个元素已更改,然后是下一个元素,依此类推.
当我需要在单击JButton时才发生这些更改时,我怎么能实现它?
**我在java中用GUI做的不太好.我希望你们在没有我提供代码的情况下理解我的观点.但如果有必要,我可以.谢谢.