Results 1 to 5 of 5
- 04-22-2009, 04:55 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 2
- Rep Power
- 0
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
- 06-09-2009, 05:06 PM #2
Member
- Join Date
- Feb 2009
- Posts
- 29
- Rep Power
- 0
it seems that "plot.java" & "landplotting.java" are two different classes and "landplotting.java" contains the main method. you can do following:
i think you should pass the parameters(south,north,east,west) from the "do_ShowArea()" methods.Java Code:main(){ do_ShowArea(); } void do_ShowArea() { System.out.println(Area()); }
good luck.Impossible is Nothing
- 06-09-2009, 07:15 PM #3
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" subforumLast 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.
- 06-09-2009, 07:48 PM #4
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:
Also, you should be using the statndard Java naming conventions: class names start with upper case letter, method names start with lower case letter, etcJava Code:plot plotClass = new plot();//instantiate plot class int area = plotClass.Area(); //shouldn't you be passing this method some parameters... south, north, etc?
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 06-10-2009, 01:12 AM #5
Similar Threads
-
Calling a method in another class
By uncopywritable in forum New To JavaReplies: 9Last Post: 10-22-2012, 04:01 PM -
Calling a method in a different class from within a method problem
By CirKuT in forum New To JavaReplies: 29Last Post: 09-25-2008, 07:55 PM -
Calling a method on original class from created class
By kpedersen in forum Advanced JavaReplies: 4Last Post: 08-20-2008, 12:25 AM -
calling a public void method from a class button
By supa_kali_frajilistik in forum AWT / SwingReplies: 1Last Post: 05-21-2008, 05:40 AM -
Calling method from another class
By asahli in forum New To JavaReplies: 1Last Post: 12-15-2007, 06:24 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks