I have tried a million different things, but Java just gives me errors or straight up doesn't work when I tell it to display an image. I have to use the default "Graphics" coordinate grid because this will result in a playable game. Please tell me (ASAP - As Simply As Possible) how to get the code below working.
import java.awt.Container;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class main extends JFrame {
static JFrame frame = new JFrame();
static Container pane = frame.getContentPane();
static Graphics graphics;
static ImageIcon background = new ImageIcon("background.png");
static JLabel backgroundLabel = new JLabel(background);
static File titleFile = new File("title.png");
static BufferedImage title;
public static void main(String[] args0) {
frame.add(backgroundLabel);
backgroundLabel.setVisible(true);
frame.setContentPane(backgroundLabel);
frame.setVisible(true);
frame.setTitle("Fastball");
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setResizable(false);
frame.pack();
try{
title = ImageIO.read(titleFile);
} catch (IOException e) {
System.out.println(e);
}finally{
};
if(title != null) {
graphics.drawImage(title, 15, 15, 440, 112, null);
}
}
}
With this code, I am getting the error Exception in thread "main" java.lang.NullPointerException at main.main(main.java:60)
and I don't know exactly what it's refering to...