Как изменить прослушиватель фокуса только на выполняемое действие, чтобы при нажатии кнопки он запускал метод затухания?
class FaderTimer implements FocusListener, ActionListener {
private ArrayList colors;
private JButton component;
private Timer timer;
private int alpha;
private int increment;
FaderTimer(ArrayList colors, JButton component, int interval) {
this.colors = colors;
this.component = component;
component.addFocusListener(this);
timer = new Timer(interval, this);
}
public void focusGained(FocusEvent e) {
alpha = 0;
increment = 1;
timer.start();
}
public void focusLost(FocusEvent e) {
alpha = steps;
increment = -1;
timer.start();
}
public void actionPerformed(ActionEvent e) {
alpha += increment;
component.setBackground((Color) colors.get(alpha));
if (alpha == steps || alpha == 0) {
timer.stop();
}
}
}
}
ActionListener
, один для кнопки и один дляTimer
- person MadProgrammer   schedule 01.10.2017