1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Problems displaying multiple images from HDD

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

  1. GullyPress

    GullyPress New Member

    Joined:
    May 26, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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:
    Code:
    public class Main{
    
        BufferedImage card;
    
        public static void main (String[] args){
            Main test = new Main();
            test.start();
        }
    
        public void start(){
            DisplayCards dc = new DisplayCards();
            card = dc.findCard();
            dc.paintCard(card);
        }
    
    
    
    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();
            frame.getContentPane().add(panel);
            frame.setSize(800,600);
            frame.setVisible(true);
            frame.setResizable(false);
            frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
            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