Getting a resource file from package folder

Reading Time: < 1 minute

I needed to acquire a media file into my project so simply in com.tugrulaslan.resources folder I’ve copied and pasted my images and in the java file i implemented the below code to use it in my app

This piece of code also allows you to set a background image for your Jframe

JLabel backgroundImage = new JLabel();
        backgroundImage.setIcon(new ImageIcon(getClass().getClassLoader().getResource("com/tugrulaslan/resources/hospitalbackgrnd.jpg")));
        backgroundImage.setLayout(new FlowLayout());