tags:

views:

58

answers:

2

I have used this statement for setting an icon for a frame but still it shows the "java" instead of my image,would you please help me?

frame.setIconImage(Toolkit.getDefaultToolkit().getImage("tictactoe.gif"));

+1  A: 

Try with ImageIcon and let us now if it works:-). It has a simple constructor taking a path to file with icon image. After construction you can retrieve image from it by calling ImageIcon.getImage().

Maybe the image is not in the right place and cannot be found?

pajton
setIconImage requires parameter of type Image. ImageIcon doesn't extend Image..
Roman
Sorry, my bad. To retrieve Image from it you additionally need to call getImage().
pajton
+2  A: 

Check if Toolkit.getDefaultToolkit().getImage("tictactoe.gif") really reads the image. Try to split into 2 lines:

Image img = Toolkit.getDefaultToolkit().getImage("tictactoe.gif");
frame.setIconImage (img);

Then use debugger to check what is there inside img variable.

Roman
Roman is right, your code is correct, but the path to the gif probably wrong. getImage will likely return null and thus the setting of the icon will not work.
Christopher Oezbek