|
-
May 3rd, 2000, 09:10 AM
#1
Elevator assignment
I hope someone can shed light on my problem !
I am a frustrated beginner, trying to complete the Deitel and Deitel assignment for an Elevator Simulation. I am aiming low, at just 2 floors and a sinlge person, but have great trouble getting calls to methods of other classes working.
If I want a method of Class B to recognize an object from Class A, I assume I would pass the object from Class A as an argument to a method in Class B, and then refer to it, but can't seem to get it to work.
Any hints ?? They would be VERY appreciated.
my private email is [email protected]
Regards
Scott
-
May 4th, 2000, 06:21 AM
#2
Re: Elevator assignment
Scott W,
I'm not 100% sure what the problem is but here is
my solution to what I think you are talking about:// ClassA
public class ClassA
{
// the object ClassB should recognize
java.awt.Rectangle rect = new java.awt.Rectangle();
// the instance of ClassB
ClassB class_B = new ClassB();
// the method to call, which in turn calls
// ClassB's method
public void callClassB()
{
classB.doSomething(rect);
}
}
// ClassB
public class ClassB
{
// the constructor... don't worry about this
public ClassB()
{
}
// the method ClassA will call...
public void doSomething(java.awt.Rectangle rect)
{
// do something with the Rectangle...
System.out.println(rect.toString());
}
}
As you can see, ClassA instanciates ClassB, then calls ClassB's doSomething() method, passing a Rectangle object.
This might not answer your question. So if there is a more specific problem you need solved, respond with more details.
Regards,
dogBear
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|