I am writing an application that performs some task and informs the user about the successful completion of the task. To tell the user, I use jlabel. I want this jlabel to display a message and disappear after a while. I use netbeans as my IDE.
Here is the architecture of my classes.
Annotation, GUI Code
abstract class Admin extends JFrame{
protected static jlabel lbl_message= new jlabel("some text");
abstarct protected void performButtonClickAction();
}
A class for implementing abstract functions and providing other functions.
final class AdminActionPerformer extends Admin{
final public void performButtonClickAction(){
if(task is successful){
new Thread(new Fader(Admin.lbl_message)).start();
}
}
public static void main(String[] args) {
new AdminActionPerformer().setVisible(true);
}
}
Thread to create jlabel slack
class Fader implements Runnable{
javax.swing.JLabel label;
Color c;
Fader(javax.swing.JLabel label){
this.label=label;
c=label.getBackground();
}
public void run() {
int alpha=label.getGraphics().getColor().getAlpha()-5;
while(alpha>0){
System.out.println(alpha);
alpha-=25;
label.getGraphics().setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), alpha));
label.repaint();
try {
Thread.sleep(50);
} catch (InterruptedException ex) {
Logger.getLogger(Fader.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
But the shortcut does not disappear. What am I doing wrong here? Thank:)
PS I set JLabel opaque. This is problem? I want to first display the shortcut with its background color, and then make it disappear.
source
share