Results 1 to 7 of 7
  1. #1
    heathy is offline Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

    Default 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

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default 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.

  3. #3
    heathy is offline Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

    Default 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:
    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)){
                 
             }
        }
    And this is what i have to do:

    + 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, Heathy
    Last edited by quad64bit; 11-18-2012 at 01:50 PM.

  4. #4
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default 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?

  5. #5
    heathy is offline Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

    Default 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

  6. #6
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: New to Java - HELP!!!!!!!

    If you have some list of files:
    Java Code:
    String[] files = {
        "/file01.png",
        "/file02.png",
        "/file03.png"
    }
    Then you can access them using indexes, for instance:
    Java Code:
    assert files[2].equals("/file02.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:
        loadPictureFromString(getPicturePathFromIndex(2));
    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().

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: New to Java - HELP!!!!!!!

    heathy, please go through the Forum Rules -- particularly the third paragraph.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Tags for this Thread

Posting Permissions

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