jeudi 26 février 2015

How do I add more images to a background Jpanel?




package Main;

import javax.swing.*;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import java.io.File;
import java.io.IOException;


public class Background {

public static void main(String[] args) {

//Window Name
JFrame F = new JFrame("Xiao's World");

//Background Image
try{
F.setContentPane(new JLabel(new ImageIcon(ImageIO.read(new File("src/Main/sky.jpg")))));

}catch(IOException e)
{
//Case if image is not available
System.out.println("Image doesn't exist.");
}

//Frame setup and rules
F.setResizable(false);
F.pack();
F.setSize(800, 600);
F.setVisible(true);

}
}


You see I can easily display a background no problem but I want a picture to be displayed on top of this background along with a few others is there a way to make a method to easily display multiply images on top of each other?


I'm trying to create a scene but it's kind of difficult because most tutorials are background imaging and not scene making. Also if you could help me so I can set up a stream of music to go alone with it that would be great, I have the images and the files I just need a code to help me set it up. I'm not that good with methods so explanations are appreciated.




Aucun commentaire:

Enregistrer un commentaire