0
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

kibar
  • 822
  • 3
  • 17
  • 37

1 Answers1

1

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);
Community
  • 1
  • 1
Michael Berry
  • 70,193
  • 21
  • 157
  • 216