views:

152

answers:

2

Hi guys! This is my 3rd SO question. Please help again... I want to put up a splashscreen on my applet. In doing so, I used the JWindow component. I already used it in creating splashscreens for my stand-alone java application so I thought it will also work on applet. The problem is, it does not work. Is Jwindow usable with applet? is there a better way to accomplish this? tnx a lot!

I instantiate LoadingScreen object in the applet's start method? Here is the code:

public class LoadingScreen extends JWindow{
private static final long serialVersionUID = 1L;
private Image image1;
private ImageIcon icon1;

public LoadingScreen(){
//image = Toolkit.getDefaultToolkit().getImage("WebContent/images/loadbar.gif");
image1 = getImage(getCodeBase(), "images/loadbar.gif");

icon1= new ImageIcon(image1);
setSize(icon1.getIconWidth(), icon1.getIconHeight());
setLocationRelativeTo(null);
setVisible(true);

try{
//Make JWindow appear for 5 seconds before disappear
Thread.sleep(5000);
dispose();
System.exit(0);
 }catch(Exception exception){
exception.printStackTrace();
}
} 
 public void paint(Graphics g){
   super.paint(g);
   g.drawImage(image1,0,0,null);
}

}

Update! Problem solved. The call to the static Thread.sleep method inside the applet start method sort of stop the resources (image) from loading.. that's why it's not showing. It was fixed by creating a separate timer Thread to do the actual counting... Just so everyone knows...:)

A: 

Why did you override the paint(...) method to display an image? Add the ImageIcon to a JLabel and add the label to the window. Then you just use the pack() method to size the window.

I don't know if a JWindow works or not. Maybe the size is zero because the image hasn't been loaded when you set the size.

Or, you could try using an undecorated JFrame.

camickr
A: 

Problem solved. The call to the static Thread.sleep method inside the applet start method sort of stop the resources (image) from loading.. that's why it's not showing. It was fixed by creating a separate timer Thread to do the actual counting... Just so everyone knows...:)

ultrajohn