Displaying image

S

Sameer

I want to display an image in an About box.
As the image was not displayed, What's wrong with this code?
Is there any other method to display image? The file WetWild.jpg is in
current directory.

import java.awt.*;
import javax.swing.*;
public class AboutBox extends JDialog {
JLabel text;
JButton buttonOK;

public AboutBox() throws HeadlessException {
text = new JLabel("Chat Server");
buttonOK = new JButton("OK");
Container cp = getContentPane();
cp.setLayout(new BorderLayout());
cp.add(text, BorderLayout.WEST);
cp.add(buttonOK, BorderLayout.EAST);
JPanel jp= new JPanel();
cp.add(jp, BorderLayout.CENTER);
pack();
Toolkit t= Toolkit.getDefaultToolkit();
Image image= t.createImage("WetWild.jpg");
Graphics g =jp.getGraphics();
g.drawImage(image,10,10,this);

buttonOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});

}
}
Do I need to pass a class which implements the ImageObserver interface
to the drawImage method? Presently the class JDialog does not implement
the
imageUpdate(Image img,
int infoflags,
int x,
int y,
int width,
int height)

method. Still the code compiles. Why is it so?

Please help.
-Sameer
 
A

Andrew Thompson

I want to display an image in an About box.
As the image was not displayed, What's wrong with this code?

It has not finised loading yet.
Do I need to pass a class which implements the ImageObserver interface
to the drawImage method? Presently the class JDialog does not implement
the imageUpdate(...) method.

Sure it does. Under the 'inheretance structure' at the
top of the page is ..

All Implemented Interfaces:
ImageObserver, ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,044
Latest member
RonaldNen

Latest Threads

Top