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
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