Results 1 to 7 of 7
Thread: New to Java - HELP!!!!!!!
- 11-18-2012, 11:45 AM #1
Member
- Join Date
- Nov 2012
- Posts
- 3
- Rep Power
- 0
New to Java - HELP!!!!!!!
Hi,
I have this assignment that requires me to add a method to my work that allows me to call another method in the same class. But, The method i initiate requires an int type whilst the one it goes on to call requires a string.
The assignment is about a pinboard where by methods are used to add picture files to an array-list and then call them, pin them up and stuff like that. This method that i am stuck on needs me to supply an int value that is checked against the index where, if it is correct, it will call a pin method where it pins the picture. but the picture is inputted into the array-list as a string. and then they conflict each other because they are different types.
i am totally stuck. Please help someone.
Heathy
- 11-18-2012, 01:39 PM #2
Re: New to Java - HELP!!!!!!!
Well, lets see the methods.
If one method expects an array index, and another a value or something similar, then this shouldn't be a problem.
- 11-18-2012, 01:45 PM #3
Member
- Join Date
- Nov 2012
- Posts
- 3
- Rep Power
- 0
Re: New to Java - HELP!!!!!!!
Hi,
This is the method I need to access:
Java Code:/** * Pin the picture in the given file to the pinboard. * An error dialog is displayed if the image cannot be read. * @param filename The picture file. */ public void pinPicture(String filename) { File selectedFile = new File(filename); OFImage image = ImageFileManager.loadImage(selectedFile); if(image != null){ ImagePanel picture = new ImagePanel(image); JInternalFrame pictureFrame = new JInternalFrame("", false, true); displayedItems.put(filename, pictureFrame); pictureFrame.add(picture); pin(pictureFrame); } else { // image file was not a valid image JOptionPane.showMessageDialog(this, "The file was not found or in a recognized image file format.", "Image Load Error", JOptionPane.ERROR_MESSAGE); } }
This is the method i need to access the above method from:
And this is what i have to do:Java Code:/** * Uses an integer to pin a file from the index * @param index The index to be accessed */ public void pin (int index) { if(validIndex(index)){ } }
+ pin: A method that takes an integer as a parameter and uses the Pinboard object
to display the image file at that index in the list. Use the pinPicture method of
Pinboard. However, if the index is not valid (too small or too large) then use the
pinNote method of the Pinboard object to pin an error message on the board.
Hope this helps, HeathyLast edited by quad64bit; 11-18-2012 at 01:50 PM.
- 11-18-2012, 01:53 PM #4
Re: New to Java - HELP!!!!!!!
Please use [code][/code] tags when posting code so we can easily read it! I've added them for you this time.
Forum Rules
Guide For New Members
BB Code List - Java Programming Forum
Right, so it looks like what I said. One method loads a file by name, the other from a file's index in an array. You wouldn't try to use a String as an array index, nor would you use an index as a file name, they are two different things.
Could you clarify what you're having trouble understanding?
- 11-18-2012, 01:57 PM #5
Member
- Join Date
- Nov 2012
- Posts
- 3
- Rep Power
- 0
Re: New to Java - HELP!!!!!!!
Hi, Thanks for code tags. Basically, I having trouble trying to figure out a way that a method that takes an "Int" can access a method that takes a string. I need to pass a int into Pin method so that it finds that corresponding file in the index and then initiates the pinPicture method to display it on a virtual Pinboard.
Thanks, Heathy
- 11-18-2012, 03:10 PM #6
Re: New to Java - HELP!!!!!!!
If you have some list of files:
Then you can access them using indexes, for instance:Java Code:String[] files = { "/file01.png", "/file02.png", "/file03.png" }
So, if you knew you wanted to load the second file, and you have two methods, one that grabs a file at an index, and another that loads a file from a string, you could do something like:Java Code:assert files[2].equals("/file02.png");
In this example, loadPictureFromString() takes a String as a param and loads it. getPicturePathFromIndex() takes an int and loads the corresponding String from an array and returns it. The result of getPicturePathFromIndex() is passed into loadPictureFromString().Java Code:loadPictureFromString(getPicturePathFromIndex(2));
- 11-18-2012, 03:52 PM #7
Re: New to Java - HELP!!!!!!!
heathy, please go through the Forum Rules -- particularly the third paragraph.
dbWhy do they call it rush hour when nothing moves? - Robin Williams


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks