JButton“保持按下状态”单击Java Applet后
我的 Java Applet 中有一个 JButton。按下按钮后,ActionListener 必须执行大量操作。因此,正因为如此,当用户单击该按钮时,它会“保持按下”一段时间(有时甚至 5 分钟),而不是立即禁用自身(它会在这 5 分钟后自行禁用)。
public void actionPerformed(ActionEvent e) {
JButton.setEnabled(false);
//...
}
我不想让用户看到这一点。我希望所有这些操作都在后台执行。我可以做什么来实现它?
I have a JButton in my Java Applet. After pressing it, ActionListener have to make huge amount of actions. So, because of it, when user clicks the button, it "stay pressed" for a while (sometimes even 5 minuts) instead of disable itself immidiately (it disable itself after these 5 minuts).
public void actionPerformed(ActionEvent e) {
JButton.setEnabled(false);
//...
}
I don't want user to see that. I would like all these action execute in the background. What can I do to achive it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该在另一个线程而不是调度程序线程中执行此类密集任务。
一些有用的阅读:工作线程和 SwingWorker
You should do such intensive tasks in another thread, not the dispatcher thread.
Some useful reading: Worker Threads and SwingWorker
问题是 GUI 线程很忙,并且在处理完成之前不会重新绘制组件
。您可以在后台线程中执行这些活动。
The problem is that the GUI-Thread is busy and will not repaint the component until processing has finsihed
You could do the activities in a backgroud thread.