I was creating an application with an image drawn in it, and it was working perfectly fine. For some reason, however, the image has stopped loading. The image is in the root folder of my project directory. Here is my code:
JFrame:
package com.cgp.tetris;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JFrame;
public class TetrisFrame extends JFrame {
private static final long serialVersionUID = 1L;
public static void main(String[] args) {
new TetrisFrame();
}
public TetrisFrame() {
add(new TetrisMenu());
setTitle("Tetris");
setSize(new Dimension(640, 576));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
setResizable(false);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
setLocation((d.width / 2) - 320, (d.height / 2) - 288);
}
}
JPanel:
package com.cgp.tetris;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
public class TetrisMenu extends JPanel implements Runnable {
private static final long serialVersionUID = 1L;
private Thread thread;
private BufferedImage titletop, titlebottom;
public TetrisMenu() {
super();
}
public void run() {
loadImages();
}
private void loadImages() {
try {
titletop = ImageIO.read(new File("tetrispic.png"));
titlebottom = ImageIO.read(new File("titlebottom.png"));
} catch (IOException e) {
e.printStackTrace();
}
}
public void addNotify() {
super.addNotify();
thread = new Thread(this);
thread.start();
}
public void paint(Graphics g) {
super.paint(g);
g.drawImage(titletop, 0, 0, 640, 440, null);
g.drawImage(titlebottom, 0, 440, null);
}
}
Thanks in advance!