.addActionListener(new ActionListener(){
public void actionPerformed (ActionEvent e){
try{
ta.append("Searching Initiated at: "+datetime()+"\n");
gui.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
task.execute();
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
gui.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
});
//Enable the next stage in the YD process and disable the previously executed functions
clusAn.setEnabled(true);
open.setEnabled(false);
statCl.setEnabled(false);
}catch (Exception IOE){
}
}
});
嗨,在这个应用程序的最后一个阶段,我设计了一点痛苦。Java SwingUtilities.invokeLater
基本上,当用户点击按钮时,我希望它使光标变成'等待'版本,然后一旦后台进程(task.execute)完成,光标将恢复正常。
task.execute不在同一个类中,所以我不能直接调用“gui.setCursor”,因为它不会将GUI识别为变量。
不知道该怎么办,所以任何建议将是巨大的
感谢:d
您不需要'actionPerformed()'中的'invokeLater()',因为它总是从GUI事件派发线程中调用。 –