Hi, I’m a beginner to Java graphics, and all I’m trying to do now is to display an image, but I have no idea why the image is not showing, all it shows is the default grey background of the JFrame object…
Here is the simple code:
import java.awt.;
import javax.swing.;
public class Test extends JPanel{
public Test()
{
Toolkit toolkit = Toolkit.getDefaultToolkit();
Image map = toolkit.getImage("map.jpg");
}
public void paintComponent(Graphics g)
{
g.drawImage(map, 0, 0, this);
}
public static void main(String args[])
{
Test thing1 = new Test();
JFrame window = new JFrame("Testing");
Container container = window.getContentPane();
container.setLayout(new FlowLayout());
container.add(thing1);
//JButton butt = new JButton("Butt");
//container.add(butt);
window.pack();
window.setVisible(true);
window.setSize(800,1100);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
I think the component that draws the image (thing1) is not showing, since I have no probelms showing a button…
Can someone please point out for me what I’m missing…I’ve spent 4 hrs already on the problem…your help would be much appreciated…thank you!