So I've been trying to teach myself the basics of Java (2D) gaming. After a long, annoying process trying to get an image to display, I got it working. Unfortunately, when I tried to add a second image, it replaced the first. I know that I'm making some obvious, noob mistake, but hey, I'm a noob at this. Anyway, here's my code:
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Main extends JFrame {
public static void main(String[] args0) {
JFrame frame = new JFrame();
ImageIcon background = new ImageIcon("background.png");
JLabel backgroundLabel = new JLabel(background);
frame.add(backgroundLabel);
backgroundLabel.setVisible(true);
ImageIcon title = new ImageIcon("title.png");
JLabel titleLabel = new JLabel(title);
frame.add(titleLabel);
titleLabel.setVisible(false);
frame.setVisible(true);
frame.setTitle("Fastball");
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.pack();
}
}
When I run this, the newly added "title.png" section overrides the first image, replacing it. Please, just tell me the simplest way to fix this with a brief explanation of my mistake.
(P.S. I'm using Eclipse Mars and the latest of all the Java stuff.)