Results 1 to 5 of 5
  1. #1
    caro is offline Member
    Join Date
    Mar 2009
    Posts
    2
    Rep Power
    0

    Question Calling a class method from another class

    Hi, am having a bit of trouble linking a propery from one class (plot.java):

    public int Area()
    {
    int height = south - north;
    int width = east - west;
    return height * width;
    }


    into my main class (landplotting.java) method:

    void do_ShowArea() {

    }


    Any ideas please?

    Thank you

  2. #2
    sayan751 is offline Member
    Join Date
    Feb 2009
    Posts
    29
    Rep Power
    0

    Default

    Quote Originally Posted by caro View Post
    Hi, am having a bit of trouble linking a propery from one class (plot.java):

    public int Area()
    {
    int height = south - north;
    int width = east - west;
    return height * width;
    }


    into my main class (landplotting.java) method:

    void do_ShowArea() {

    }


    Any ideas please?

    Thank you
    it seems that "plot.java" & "landplotting.java" are two different classes and "landplotting.java" contains the main method. you can do following:

    Java Code:
    main(){
    do_ShowArea();
    }
    
    void do_ShowArea() {
             System.out.println(Area());
    }
    i think you should pass the parameters(south,north,east,west) from the "do_ShowArea()" methods.

    good luck.
    Impossible is Nothing

  3. #3
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default NetBeans?

    Does this post have anything to do with NetBeans? If, I will move to the "New to Java" subforum.

    CJSL

    Edit: Post moved from "NetBeans" subforum
    Last edited by CJSLMAN; 06-09-2009 at 07:24 PM. Reason: Updated to indicate that the post was moved
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  4. #4
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default

    I'm not sure if I understand the question/doubt. I think you want call a class's method (plot.java) from your main class (landplotting.java). If so, then you would have to instantiate the plot class in the landplotting class and then call the method:
    for example:

    Java Code:
    plot plotClass = new plot();//instantiate plot class
    int area = plotClass.Area(); //shouldn't you be passing this method some parameters... south, north, etc?
    Also, you should be using the statndard Java naming conventions: class names start with upper case letter, method names start with lower case letter, etc
    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  5. #5
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default Zombie alert

    WARNING: this post (which I also answered... duh) is almost two months old... probably no need for further discussion.

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Similar Threads

  1. Calling a method in another class
    By uncopywritable in forum New To Java
    Replies: 9
    Last Post: 10-22-2012, 04:01 PM
  2. Replies: 29
    Last Post: 09-25-2008, 07:55 PM
  3. Calling a method on original class from created class
    By kpedersen in forum Advanced Java
    Replies: 4
    Last Post: 08-20-2008, 12:25 AM
  4. calling a public void method from a class button
    By supa_kali_frajilistik in forum AWT / Swing
    Replies: 1
    Last Post: 05-21-2008, 05:40 AM
  5. Calling method from another class
    By asahli in forum New To Java
    Replies: 1
    Last Post: 12-15-2007, 06:24 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
  •