Results 1 to 7 of 7
- 10-02-2010, 06:22 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 12
- Rep Power
- 0
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();**
}
- 10-02-2010, 07:04 PM #2
Remove the call to FileChooser from the constructor and put what it returns in a variable.
- 10-03-2010, 05:22 PM #3
Member
- Join Date
- Sep 2010
- Posts
- 12
- Rep Power
- 0
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.
- 10-03-2010, 05:40 PM #4
Here is what I meant:what code do I use to display the previous picture without having to select it again
File aFile = FileChooser.pickAFile();
// now the variable aFile can be used other places
new Picture(aFile);
- 10-03-2010, 05:46 PM #5
Member
- Join Date
- Sep 2010
- Posts
- 12
- Rep Power
- 0
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;
}
- 10-03-2010, 05:53 PM #6
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.
- 10-03-2010, 06:05 PM #7
Member
- Join Date
- Sep 2010
- Posts
- 12
- Rep Power
- 0
Similar Threads
-
Accessing metadata of files
By LianaN in forum New To JavaReplies: 11Last Post: 09-19-2010, 05:49 PM -
Randomly accessing files
By Java Tip in forum Java TipReplies: 0Last Post: 12-12-2007, 10:46 AM -
Accessing index.dat files
By vissu007 in forum NetworkingReplies: 1Last Post: 07-01-2007, 04:47 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks