JButton“保持按下"状态在Java Applet中单击后 [英] JButton "stay pressed" after click in Java Applet

查看:246
本文介绍了JButton“保持按下"状态在Java Applet中单击后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Java Applet中有一个JButton.按下它之后,ActionListener必须执行大量操作.因此,由于这个原因,当用户单击按钮时,它会保持按下"状态一段时间(有时甚至是5分钟),而不是立即禁用自身(在这5分钟后会禁用自身).

public void actionPerformed(ActionEvent e) {
  JButton.setEnabled(false);
  //...
}

我不希望用户看到它.我希望所有这些操作都在后台执行.我该怎么做才能达到目标?

解决方案

您应该在另一个线程(而不是调度程序线程)中执行此类繁重的任务.

一些有用的读物​​:工作线程和SwingWorker

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?

解决方案

You should do such intensive tasks in another thread, not the dispatcher thread.

Some useful reading: Worker Threads and SwingWorker

这篇关于JButton“保持按下"状态在Java Applet中单击后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆