Results 1 to 7 of 7
  1. #1
    t0nydanzuh is offline Member
    Join Date
    Sep 2010
    Posts
    12
    Rep Power
    0

    Default Need help with accessing files in a method

    I have a program in which I'm making selections from a menu and each selection must do something different. As shown below, the first selection chooses a picture file and displays it to be able to process. The second method needs to take that picture and display it, what code do I use to display the previous picture without having to select it again? I've been trying everything I know and it's frustrating me like crazy. Any help would be appreciated.

    Here is a snippet of the code, the p.show() is wrong, I'm looking for what should go there...


    private void ProcessPicture(java.io.InputStream input){
    //Scanner in = new Scanner(input);
    Picture p =
    new Picture(FileChooser.pickAFile());
    p.explore();
    }
    private void DisplayPicture(java.io.InputStream input){
    **p.show();**
    }

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,395
    Rep Power
    25

    Default

    Remove the call to FileChooser from the constructor and put what it returns in a variable.

  3. #3
    t0nydanzuh is offline Member
    Join Date
    Sep 2010
    Posts
    12
    Rep Power
    0

    Default

    this still isn't helping me, is there another way I could possibly do that?

    The FileChooser needs to be there in order for it to let the user search for a file to use.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,395
    Rep Power
    25

    Default

    what code do I use to display the previous picture without having to select it again
    Here is what I meant:
    File aFile = FileChooser.pickAFile();
    // now the variable aFile can be used other places
    new Picture(aFile);

  5. #5
    t0nydanzuh is offline Member
    Join Date
    Sep 2010
    Posts
    12
    Rep Power
    0

    Default

    2 errors found:
    File: C:\Users\Steve\Desktop\CS260\java-source\PictureMenu.java [line: 504]
    Error: C:\Users\Steve\Desktop\CS260\java-source\PictureMenu.java:504: incompatible types
    found : java.lang.String
    required: java.io.File
    File: C:\Users\Steve\Desktop\CS260\java-source\PictureMenu.java [line: 506]
    Error: C:\Users\Steve\Desktop\CS260\java-source\PictureMenu.java:506: cannot find symbol
    symbol : constructor Picture(java.io.File)
    location: class Picture

    private void ProcessPicture(java.io.InputStream input){
    //Scanner in = new Scanner(input);
    File aFile = FileChooser.pickAFile(); //line 504
    Picture p =
    new Picture(aFile); //line 506

    //return p;
    }

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,395
    Rep Power
    25

    Default

    I didn't have the doc for the pickAFile method and did not have the specs for the Picture constructor. I left that to you. Change the line to use the correct type:
    <TheNeededTypeHere> aFile = FileChooser.pickAFile();
    Last edited by Norm; 10-03-2010 at 05:55 PM.

  7. #7
    t0nydanzuh is offline Member
    Join Date
    Sep 2010
    Posts
    12
    Rep Power
    0

    Default

    sorry im just over frustrating myself. Thanks for the help

Similar Threads

  1. Accessing metadata of files
    By LianaN in forum New To Java
    Replies: 11
    Last Post: 09-19-2010, 05:49 PM
  2. Randomly accessing files
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-12-2007, 10:46 AM
  3. Accessing index.dat files
    By vissu007 in forum Networking
    Replies: 1
    Last Post: 07-01-2007, 04:47 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
  •