Getting a resource file from package folder

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());
        add(backgroundImage);

Leave a Reply

Your email address will not be published. Required fields are marked *