I've added a background to my Java Applet, I need some help understanding why the applet isn't displaying properly. To display this background image I've used the code seen below:
BufferedImage img = null;
try {
URL url = new URL(getCodeBase(), "Backgrounds/Background.png");
img = ImageIO.read(url);
}
catch (Exception e) {
}
then also put this in the paint method...
public void paint(Graphics g) {
g.drawImage(img, 0, 0, null);
}
The problem is that you cannot see the GUI components such as buttons and labels when the background is painted, even though the background is painted before the other GUI components are added to the content pane. It is possible to get the components to appear but you have to highlight them or click on them first.
This picture shows the applet when the applet is loaded:
Then this is the applet after I have clicked in a few places on screen: