00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 package ikayaki.gui;
00024
00025 import javax.swing.*;
00026 import java.awt.*;
00027 import java.awt.event.ActionEvent;
00028 import java.awt.event.ActionListener;
00029
00035 public class ComponentFlasher extends Timer {
00036
00037 private final JComponent component;
00038 private final Color componentBG;
00039 private final Color flashcolor;
00040 private static final Color defauldFlashColor = new Color(0xff6060);
00041
00042 public ComponentFlasher(JComponent component) {
00043 this(component, defauldFlashColor, 100);
00044 }
00045
00046 public ComponentFlasher(JComponent component, Color flashcolor) {
00047 this(component, flashcolor, 100);
00048 }
00049
00050 public ComponentFlasher(JComponent component, int flashtime) {
00051 this(component, defauldFlashColor, flashtime);
00052 }
00053
00054 public ComponentFlasher(JComponent component, Color flashcolor, int flashtime) {
00055 super(flashtime, null);
00056 this.component = component;
00057 this.componentBG = component.getBackground();
00058 this.flashcolor = flashcolor;
00059 this.setRepeats(false);
00060
00061 this.addActionListener(new ActionListener() {
00062 public void actionPerformed(ActionEvent e) {
00063 ComponentFlasher.this.component.setBackground(componentBG);
00064 }
00065 });
00066 }
00067
00068 public void flash() {
00069 component.setBackground(flashcolor);
00070 super.start();
00071 }
00072 }