I am trying to load multiple jpeg files into java using BufferedImage. I can load and display one file using;
BufferedImage loadImg = loadImage('trial0001.jpg);
When I try to add a second file, all I get is error messages.
Thoughts please.
Thanks

Recommended Answers

All 3 Replies

Read the documentation for this yet? What about Google/Oracle?

If you showed us the code and told us what the error messages were, then maybe we could help.

First off, thanks for taking time to reply.
I did look at the tutorials. The first projram worked (load then output one jpg). I tried to upscale and lost it. My goal is to get about 30 to 40 jpgs to load then display in jpanels. Then I'll manipulate the files. Here is the code so far. I included the errors in the code. They are repetitive.

import java.awt.*;
import java.awt.image.*;
import javax.imageio.ImageIO;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.swing.JPanel;

public class ImageAppFour {

    public void loadAndDisplayImage(JFrame frame) {
        BufferedImage loadImgMaster = loadImage("master.jpg");
    BufferedImage Teacher = loadImage("teacher.jpg");
    BufferedImage Child = loadImage("marthajefferson.jpg");

//*********************************************************************************
// here starts a series of errors.
//ImageAppFour.java:18: error: cannot find symbol
//        BufferedImage loadImgMaster = loadImage("master.jpg");
//                                      ^
//  symbol:   method loadImage(String)
//  location: class ImageAppFour
//ImageAppFour.java:19: error: cannot find symbol
//        BufferedImage Teacher = loadImage("teacher.jpg");
//                                ^
//  symbol:   method loadImage(String)
//  location: class ImageAppFour
//ImageAppFour.java:20: error: cannot find symbol
//        BufferedImage Child = loadImage("marthajefferson.jpg");
//*********************************************************************************



    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Dimension dimension = toolkit.getScreenSize();
    frame.setBounds(0, 0, dimension.width-30,  dimension.height - 50 );

        JImagePanel imagePanel1 = new JImagePanel(loadImgMaster, 0, 0);
        JImagePanel imagePanel2 = new JImagePanel(loadImgTeacher, 0, 0);
        JImagePanel imagePanel3 = new JImagePanel(loadImgChild, 0, 0);


//*********************************************************************************
// now a second set of errors, but I notice ***loadImgMaster*** is not an error
//
//
//ImageAppFour.java:27: error: cannot find symbol
//        JImagePanel imagePanel2 = new JImagePanel(loadImgTeacher, 0, 0);
//                                                  ^
// symbol:   variable loadImgTeacher
//  location: class ImageAppFour
//ImageAppFour.java:28: error: cannot find symbol
//        JImagePanel imagePanel3 = new JImagePanel(loadImgChild, 0, 0);
//*********************************************************************************

        imagePanel.setPreferredSize(new Dimension(
        loadImgMaster.getWidth(), loadImgMaster.getHeight()));

    JScrollPane scrollPane = new JScrollPane();
    scrollPane.getViewport().add(imagePanel);

    JPanel topPanel = new JPanel();
    topPanel.setLayout( new BorderLayout() );
    topPanel.add( scrollPane, BorderLayout.CENTER );

    frame.getContentPane().add(topPanel);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();

    frame.setSize(500, 300); 
        frame.setVisible(true);

    }

    public static BufferedImage loadImageMaster(String ref) {
            BufferedImage bimg = null;
            try {

                bimg = ImageIO.read(new File(ref));
            } catch (Exception e) {
                e.printStackTrace();
            }
            return bimg;
        }
    public static void main(String[] args) {
        ImageApp ia = new ImageApp();
        JFrame frame = new JFrame("Athena - Goddess of Wisdom");
        ia.loadAndDisplayImage(frame);
    }

}

class JImagePanel extends JPanel{
    private BufferedImage image;
    int x, y;
    public JImagePanel(BufferedImage image, int x, int y) {
        super();
        this.image = image;
        this.x = x;
        this.y = y;
    }
    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawImage(image, x, y, null);
    }

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.