【发布时间】:2010-10-17 05:21:40
【问题描述】:
我有一个JButton,按下它时,背景颜色会从活动变为正常:
final Color activeButtonColor = new Color(159, 188, 191);
final Color normalButtonColor = new Color(47, 55, 56);
我想在特定任务完成执行后将活动按钮颜色淡化回正常按钮颜色。我正在使用SwingWorker 并想知道是否有人可以建议一种有效的方法来做到这一点?
button.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent event) {
new SwingWorker<Object, Object>() {
protected Object doInBackground() throws Exception {
button.setBackground(activeButtonColor);
for (int note = 60; note < 120; note++) {
midiController.sendMidiMessage(1, note, 83);
midiController.stopMidiMessage(note, 83);
}
Thread.sleep(200);
return null;
}
protected void done() {
try {
Object result = get();
// Fade back
} catch (Exception ex) {
ex.printStackTrace();
if (ex instanceof java.lang.InterruptedException)
return;
}
}
}.execute();
}
});
编辑:为了清楚起见,我正在寻找一种有效的方法将 activeButtonColor 的 RGB 值淡化回 normalButtonColor,而无需创建大量 @987654327 @对象。可能吗?还是我只需要限制淡入淡出步骤的数量以提高效率?
【问题讨论】:
标签: java user-interface swing awt swingworker