Here is a simple class to just highlight the use of Frame Object. I am however at the same time interested in getting an image icon, or title icon or applet icon, what ever is the proper name. I thought of using the setIconImage method but on checking it, I realized that an image object is required. This is where I got stomped as the image class has all sort of methods and apparently all kinds of other methods have to be used. I am hoping this is not the case. The image I intend to use is in the .ico format and is placed in the same folder as the class I am using. Here is the code thus far that works.
I have highlighted my attempt to put the icon image in the frame. This is a very simple class that simply hides and shows a frame based on the click of a button.Code://FrameDemo
//Demonstrates a very simple frame
//Danon Knox, 05/00
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class FrameDemo extends Applet implements ActionListener
{
Frame frmHello = new Frame("Hello There!");
Button btnShowFrame = new Button("Show Frame");
Button btnHideFrame = new Button("Hide Frame");
[COLOR="Red"] //this is where i failed to instantiate the image object
//Image favicon = getIconImage("favicon.ico");[/COLOR]
public void init()
{
add(btnShowFrame);
add(btnHideFrame);
btnShowFrame.addActionListener(this);
btnHideFrame.addActionListener(this);
frmHello.setFont(new Font("SansSerif", Font.BOLD, 30));
frmHello.add(new Label("Hello there!"), BorderLayout.CENTER);
[COLOR="red"]// this was my failed attempt
//frmHello.setIconImage(favicon);[/COLOR]
}//end init
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == btnShowFrame)
{
frmHello.setVisible(true);
frmHello.setSize(100,100);
frmHello.pack();
}
else
{
frmHello.setVisible(false);
frmHello.dispose();
}
}
}