Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Calling this method

    Super noobie question but I don't have a clue..
    Code:
      public void changeWhole(double amount)
      {
        Pixel[] pixelArray = this.getPixels();
        Pixel pixel = null;
        int value = 0;
        int i = 0;
        while( i < pixelArray.length)
        {
          pixel = pixelArray[i];
          value = pixel.getBlue();
          pixel.setBlue((int) (value * amount));
          i++;
        }
      }
      
      
      public static void main(String[] args) 
      {
         String fileName = FileChooser.pickAFile();
         Picture pictObj = new Picture(fileName);
         pictObj.explore();
      }
    I dont know how to call the changeWhole method in the main method without getting any errors.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Is the class this method resides in "Picture"? If so, you can just use in the main: pictObj.changeWhole(50.0); for example. That should be the correct way to call it.
    That doesn't mean you won't get other errors, but the method itself appears to be written to prevent errors as much as possible. The only one that should be possible to throw an error is pixelArray.length, which will only occur if this.getPixels() returns void or null.
    That assumes you are not referring to a compilation error though.


  •  

    Posting Permissions

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