Results 1 to 3 of 3
  1. #1
    antnas is offline Member
    Join Date
    Oct 2012
    Posts
    15
    Rep Power
    0

    Default Calling this method

    Java 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 * 0.9));
          i++;
        }
      }
      
      
      public static void main(String[] args) 
      {
         String fileName = FileChooser.pickAFile();
         Picture pictObj = new Picture(fileName);
         pictObj.explore();
      }
    I want to call the changeWhole method in my main method but I don't have any idea on how to type it out.

  2. #2
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: Calling this method

    How about making the changeWhole method static and then:
    Java Code:
    public static void main(String[] args)
     {
        String fileName = FileChooser.pickAFile();
        Picture pictObj = new Picture(fileName);
        pictObj.explore();
        changeWhole(0); // 0 as amount variable is not used within the method
     }
    OR create an object of your class (which you did not mention, so I call it XXX)

    public static void main(String[] args)
    {
    String fileName = FileChooser.pickAFile();
    Picture pictObj = new Picture(fileName);
    pictObj.explore();

    XXX main = new XXX();
    main.changeWhole(0); // 0 as amount variable is not used within the method
    }
    [/Code]
    Last edited by Sierra; 11-03-2012 at 09:39 AM.
    I like likes!

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

    Default Re: Calling this method

    Quote Originally Posted by Sierra View Post
    How about making the changeWhole method static
    And how do you propose to use this.getPixels() in a static method?

    The correct approach is to create an instance of the class and invoke the method on that instance.

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

Similar Threads

  1. calling on method
    By FREDISCO in forum New To Java
    Replies: 1
    Last Post: 03-27-2012, 11:08 PM
  2. Thread problem, calling method in run method
    By majk in forum Threads and Synchronization
    Replies: 4
    Last Post: 09-27-2010, 11:40 AM
  3. Calling The main method from another method
    By SwissR in forum New To Java
    Replies: 3
    Last Post: 07-27-2010, 11:03 AM
  4. calling method from main method
    By bob_bee in forum New To Java
    Replies: 4
    Last Post: 10-02-2009, 05:30 PM
  5. Replies: 29
    Last Post: 09-25-2008, 07:55 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
  •