JFrame "reshowing"

Hi,

I have a problem with Frame refreshing or rather "reshowing".

I know that there are similar topics but in none of them I found

solution.

I need to make a window which simply appears and disappears

in certain time intervals. The problem is that when it appears

for the >=second time it is nothing but a grey rectangle.

So which methods do I have to use?

class NotifyFrameextends JFrame{

public NotifyFrame(){

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setTitle("Notifying");

setPreferredSize(new Dimension(300, 150));

pack();

setVisible(true);

final JFrame frame =this;

new Timer(3000,new ActionListener(){

publicvoid actionPerformed(ActionEvent e){

validate();

repaint();

setVisible(true);

try{

Thread.sleep(1000);

}catch(Exception ex){

ex.printStackTrace();

}

setVisible(false);

}

}).start();

}

}

[1839 byte] By [Java_vigenera] at [2007-11-26 15:31:19]
# 1
Have you considered JOptionPane.showXXXX() inside your timer?
es5f2000a at 2007-7-8 21:48:10 > top of Java-index,Desktop,Core GUI APIs...
# 2
a Swing Timer runs its events on the EDT, which means your code that sleeps for 1 second between setVisible(true) and setVisible(false) is blocking the EDT, and therefore, blocking all painting. You need to start another timer to signal when to hide the frame again.
Jasprea at 2007-7-8 21:48:10 > top of Java-index,Desktop,Core GUI APIs...