1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Problems displaying multiple images from HDD

Discussion in 'Java' started by GullyPress, May 26, 2011.

  1. GullyPress

    GullyPress New Member

    I have written a class to pull an image(s) from my HDD by pathname and I want to use the BufferImage class to read the image and then use the Graphics class from .AWT to drawImage onto the contentPane of my Frame. I have set up the drawImage in a for loop because I want to reproduce the image 5 times onto different areas using absolute position but the method is giving me a blank container. Any help? Here are the two classes

    Main class:
    public class Main{
        BufferedImage card;
        public static void main (String[] args){
            Main test = new Main();
        public void start(){
            DisplayCards dc = new DisplayCards();
            card = dc.findCard();
    Display class:
     public BufferedImage findCard(){
            try {
                System.out.println("Enter filepath\n");
                BufferedReader bf = new BufferedReader
                        (new InputStreamReader(System.in));
                String imageName = bf.readLine();
                File inputFile = new File(imageName);
                tempImage = ImageIO.read(inputFile);
            } catch (IOException ie) {
                System.out.println("Error:" + ie.getMessage());
            return tempImage;
        public void paintCard(BufferedImage image){
            JFrame frame = new JFrame("Card Game");
            Panel panel = new DisplayCards();
            Graphics g;
            g = frame.getContentPane().getGraphics();
            g.drawImage(image, 100, 100, null);
           for (int i=0; i<5; i++){
            g.drawImage(image, (i * 150 + 25), 50, null);
    Last edited by a moderator: May 26, 2011

Share This Page