i have two solutions might help you :
import javax.imageio.ImageIO ;
import javax.swing.JPanel ;
import java.awt.image.BufferedImage ;
import javax.swing.ImageIcon ;
import java.awt.Graphics ;
import java.awt.Graphics2D ;
import java.io.IOException ;
public class LoadImage extends JPanel {
BufferedImage bufferedImage ;
ImageIcon image ;
public LoadImage() {
// If you want to load your image inside the resources, do this
try {
bufferedImage = ImageIO.read(getClass().getResourceAsStream("/your/location.png"));
} catch (IOException e) {
e.printStackTrace() ;
}
// do this if you want to load your image outside the program
image = new ImageIcon("path/to/your/location.png") ;
}
@Override
public void paintComponent(Graphics g) {
// for bufferedImage
if (bufferedImage != null) {
g.drawImage(bufferedImage, 0, 0, null) ;
}
// for image
if (image != null) {
g.drawImage(image.getImage(), 0, 0, null) ;
}
}
}
i have a library that can handle your loading files, saves, images, wav musics from various locations named JStreamLoader, you can check it if you want. JStreamLoader library on GitHub