Results 1 to 5 of 5
  1. #1
    swedishfished is offline Member
    Join Date
    Sep 2012
    Posts
    42
    Rep Power
    0

    Default Mac: Can't read input file, when adding pictures to a JFrame

    hey guys, title kinda says it all. i've tried changing the path 10000 times. idk if its wrong in the code. help please! thanks,
    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    
    import javax.swing.*;
    
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    
    import javax.imageio.ImageIO;
    
    public class calculator extends JPanel{
    	String addPath = "/Users/swedishfished/Desktop/eclipse/calcuLater\\!/src/add.png";
    	String subtractPath = "/Users/swedishfished/Desktop/eclipse/calcuLater\\!/src/subtract.png";
    	String multiplyPath = "/Users/swedishfished/Desktop/eclipse/calcuLater\\!/src/multiply.png";
    	String dividePath = "/Users/swedishfished/Desktop/eclipse/calcuLater\\!/src/divide.png";
    	
    	
    	private JFrame frame;
    	calculator() throws IOException{
    		frame = new JFrame("wassup");
    		frame.setSize(500,500);
    		frame.add(this);
    		frame.setVisible(true);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);		
    		File add = new File(addPath);
    		File subtract = new File(subtractPath);
    		File multiply = new File(multiplyPath);
    		File divide = new File(dividePath);
    		
            BufferedImage a = ImageIO.read(add);
            BufferedImage s = ImageIO.read(subtract);
            BufferedImage m = ImageIO.read(multiply);
            BufferedImage d = ImageIO.read(divide);
            JLabel aLabel = new JLabel(new ImageIcon(a));
            JLabel sLabel = new JLabel(new ImageIcon(s));
            JLabel mLabel = new JLabel(new ImageIcon(m));
            JLabel dLabel = new JLabel(new ImageIcon(d));
            frame.add(aLabel);
       //     aLabel.setLocation(200,200);
            
            frame.add(mLabel);
        //    mLabel.setLocation(600,200);
    
            frame.add(sLabel);
        //    sLabel.setLocation(200,600);
    
            frame.add(dLabel);
          //  dLabel.setLocation(600,600);
    
            
    	}
    	
    	
    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,038
    Rep Power
    10

    Default Re: Mac: Can't read input file, when adding pictures to a JFrame

    What do those paths represent? What's with the exclamation marks? Is that a mac thing?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    swedishfished is offline Member
    Join Date
    Sep 2012
    Posts
    42
    Rep Power
    0

    Default Re: Mac: Can't read input file, when adding pictures to a JFrame

    i don't know. i also tried to use the paths for the folder "./add.png" but it did not work

  4. #4
    swedishfished is offline Member
    Join Date
    Sep 2012
    Posts
    42
    Rep Power
    0

    Default Re: Mac: Can't read input file, when adding pictures to a JFrame

    nvm i got it to work ignore

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,891
    Rep Power
    25

    Default Re: Mac: Can't read input file, when adding pictures to a JFrame

    i got it to work
    Please post the solution in case others have the same problem.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. adding pictures to a button:
    By jocdrew21 in forum New To Java
    Replies: 2
    Last Post: 05-18-2014, 09:17 PM
  2. Album Class Adding the pictures
    By antnas in forum New To Java
    Replies: 2
    Last Post: 12-09-2012, 06:36 AM
  3. read input file into array
    By randoms:) in forum New To Java
    Replies: 3
    Last Post: 04-23-2011, 09:52 AM
  4. read only double input from text file
    By napi1234 in forum New To Java
    Replies: 6
    Last Post: 06-28-2010, 05:06 PM
  5. read a specific line in an input file
    By sara12345 in forum Advanced Java
    Replies: 7
    Last Post: 01-03-2010, 11:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •