Hi,
I am using a sample jpg picture from my computer stored in the src of the program.
It is not displaying the picture on the window.Code:package game1;
import java.awt.*;
import javax.swing.*;
public class Game1 extends JFrame {
private Insets insets;
private final int WIDTH = 800, HEIGHT = 600;
private Graphics g;
private Image imageBuffer;
public Game1() {
setVisible(true);
insets = getInsets();
setSize(WIDTH + insets.left + insets.right, HEIGHT + insets.top +
insets.bottom);
setTitle("Game1");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setResizable(false);
if (((imageBuffer = createImage(WIDTH, HEIGHT)) != null) &&
((g = imageBuffer.getGraphics()) != null))
drawGame();
else
System.exit(1);
}
public void paint(Graphics g) {
if (imageBuffer != null)
g.drawImage(imageBuffer, insets.left, insets.top, null);
}
private void drawGame() {
Image img;
img = Toolkit.getDefaultToolkit().createImage("Lighthouse.jpg");
g.drawImage(img, insets.left, insets.top, null);
repaint();
}
public static void main(String[] args) {
Game1 game = new Game1();
}
}
Any help?
