Hi, Nathan
This is what I did:
I created a class IndicatorPanel it flashes a message on a panel and flashes an Icon.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import com.siac.secmon.ExceptionHandler;
public class IndicatorPanel extends JPanel {
JLabel lbError = new JLabel();
String noError = new String(" ");
String Error = new String("!!! NEW MESSAGE ARRIVED !!!");
Thread flash = new Flash();
JFrame frame = null;
Image[] icons = null;
private boolean shouldFlash = false;
public IndicatorPanel(JFrame frame) {
BoxLayout lytErrorPanel = new BoxLayout(this,BoxLayout.X_AXIS);
this.setLayout(lytErrorPanel);
this.frame = frame;
lbError.setText(noError);
this.add(Box.createHorizontalGlue());
this.add(lbError);
this.add(Box.createHorizontalGlue());
if(frame != null){
icons = new Image[3];
icons[0]=Toolkit.getDefaultToolkit().createImage(MainFrame.class.getResource("SmileyAngry.jpg"));
icons[1]=Toolkit.getDefaultToolkit().createImage(MainFrame.class.getResource("SmileyAngry1.jpg"));
icons[2]=Toolkit.getDefaultToolkit().createImage(MainFrame.class.getResource("Smiley2.jpg")); }
}
public void startFlashing(){
if (! shouldFlash){
shouldFlash = true;
new Flash().start();
}
}
public void stopFlashing(){
shouldFlash = false;
}
private class Flash extends Thread{
public void run(){
while(shouldFlash){
lbError.setText(Error);
lbError.setForeground(Color.red);
lbError.updateUI();
if(frame != null){
frame.setIconImage(icons[0]);
}
try{
Thread.currentThread().sleep(200);
}catch(InterruptedException ie){
} // end try
lbError.setForeground(Color.black);
lbError.updateUI();
if(frame != null){
frame.setIconImage(icons[1]);
}
try{
Thread.currentThread().sleep(200);
}catch(InterruptedException ie){
} // end try
}// end while
lbError.setText(noError);
lbError.updateUI();
if(frame != null){
frame.setIconImage(icons[2]);
}
}
}
}// END :~
I add the panel to a frame and pass the frame as an arg.
It works fine on WIN but once I put it on Solaris 2.6 the Icon does not get loaded at all. I can see some pic after minimizing the frame, it even changes color the way it suppose to, but teh image is very unclear. It is like watching TV with very bad reception.
Do you know why?
Thank you, Yarik.