Java Placing Frame Icon

Java Placing Frame Icon

Summary: Learn in this tutorial "Java Placing Frame Icon", how to place your own icon on the frame (in place of default coffee cup) title bar.

In the following program, our own choice of icon (bird) is placed on the frame title bar. It replaces the default coffee cup. The frame is also made non-resizable with setResizable() method.

import java.awt.*;
import java.awt.event.*;
public class FrameIcon extends Frame
{
  public FrameIcon()
  {
    setTitle("Frame Icon");

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

    setResizable(false);

    setSize(350, 200);
    setVisible(true);
  }
  public static void main(String args[])
  {
    new FrameIcon();
  }
}

Java Placing Frame Icon

Observe the bird image on the title bar.

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

Any image to be placed on the frame should be converted into an object of java.awt.Image class. The image object is returned by getImage() method of Toolkit class.

 
           setResizable(false);

The above statement makes the frame non-resizable by the user.

All the remaining code is as usual.

4 thoughts on “Java Placing Frame Icon”

  1. sir!!!replacing coffee cup program is not working for me..i have exceuted the same code…can you tell the reason

Leave a Comment

Your email address will not be published.