I'm having a problem putting multiple images on a JFrame. I already added a picture on the JFrame as the primary background. But when I try to put another image for the logo of my program, it doesn't show up. Can someone please help me? thanks.
P.S. I'm using the Container class in my JFrame.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.event.*;
import java.io.*;
import java.awt.Container;
public class logIn extends JFrame
{
Random rand = new Random();
int n2 = (int) (1+Math.random()*255);
int n1 = rand.nextInt(n2);
int n3 = rand.nextInt(n2);
int n4 = rand.nextInt(n2);
Color color = new Color(n1,n3,n4);
JLabel image = new JLabel (new ImageIcon("space2.png"));
//JLabel image2 = new JLabel (new ImageIcon("login.png"));
JLabel userName = new JLabel("Username");
JLabel passWord = new JLabel("Password");
JTextField user = new JTextField(10);
JTextField pass = new JTextField(10);
JLabel myDog = new JLabel(new ImageIcon("space.jpeg"));
public static void main (String args[])
{
new logIn();
}
public logIn()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(null);
c.add(image);
image.setBounds(0,0,1366,768);
JLabel image2 = new JLabel (new ImageIcon("login.png"));
c.add(image2);
image2.setBounds(2000,2000,2000,2000);
//c.add(image2);
//image2.setBounds(10,10,250,250);
//c.add(userName);
//userName.setLayout(null);
//userName.setBounds(50,100,100,50);
setVisible(true);
setSize(1366,768);
setLayout(new BorderLayout());
add(myDog);
myDog.setLayout(null);
}
public void paint (Graphics g)
{
Image a = Toolkit.getDefaultToolkit().getImage("login.png");
g.drawImage(a,0,0,1366,768,this);
super.paint(g);
setVisible(true);
}
}