kibar
kibar

Reputation: 824

Java BufferedImage not work

public class image {
    JFrame pen = new JFrame();

    public image () {
        pen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        pen.setBounds(150, 100, 613, 231);
        pen.setVisible(true);

        try {
            URL url = new URL("http://images2.layoutsparks.com/1/56178/castle-stone-window-grey.jpg");
            BufferedImage bI = ImageIO.read(url);
            ImageIO.write(bI, "jpg", new File("C:\\kibAr.jpg"));
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}

I dont have error but dont work why?(I want to use BufferedImage)

And how i can set the window background this graphic?

Sory for my bad english

Upvotes: 0

Views: 412

Answers (1)

Michael Berry
Michael Berry

Reputation: 72284

If by work you mean display the BufferedImage on the frame, then that's because there's no code where you're actually adding it to the frame at all!

You may wish to have a look here for some examples of how to do this.

The quickest way would probably be something along the lines of:

JLabel picLabel = new JLabel(new ImageIcon(bI));
pen.add(picLabel);

Upvotes: 1

Related Questions