ok, erm.. in one class I have calculated a value 'total' now I want it to add to another total in another class that extends the same class. how do i take that value and add it to another in another class?
Hope this helps to get your value from one class to another class. Davy [ March 03, 2004: Message edited by: Davy Kelly ]
How simple does it have to be???
Karis Brown
Ranch Hand
Joined: Nov 13, 2003
Posts: 33
posted
0
thanks davy!! i will try it out
Karis Brown
Ranch Hand
Joined: Nov 13, 2003
Posts: 33
posted
0
i do that but it inherits all the controls from the previous panel doubling up on checkboxes! is there a way to avoid this?
Davy Kelly
Ranch Hand
Joined: Jan 12, 2004
Posts: 384
posted
0
Karis, Find the variable, that you want to get (total which you were chatting about), you could make it private in the class that it is in, then make an object of that class to access the variable that you want. I have ammended the code to include a private variable and a get method, so that you can access the variable.
e.g.
does this help? Davy [ March 03, 2004: Message edited by: Davy Kelly ]
Give us more detail...it's rare to have a subclass contain a reference to an instance of a super class and be accessing its data in the way you describe. Perhaps your design could be improved and this problem will solve itself. sev
Karis Brown
Ranch Hand
Joined: Nov 13, 2003
Posts: 33
posted
0
thanks even though looking at this i am completely lost, but i'm sure i will get the knack of it eventually.
Davy Kelly
Ranch Hand
Joined: Jan 12, 2004
Posts: 384
posted
0
Karis, Post some of your code and someone will see what is going on. use the code button below the Add Reply button and place you code between the tags, this way it keeps indentation. no doubt you will get a response which is more accurate to your neeeds. Davy
Karis Brown
Ranch Hand
Joined: Nov 13, 2003
Posts: 33
posted
0
HELP! i get ---------- Java Complier ---------- A2PizzaProgram.java:115: non-static method getTotal() cannot be referenced from a static context double total = pSc.getTotal(); ^ 1 error Normal Termination Output completed (0 sec consumed). [ March 08, 2004: Message edited by: Karis Brown ]
You can't use non-static methods in static context. What do I mean by that? Well: class ClassA { public String aMethod() { return "Hello"; }
public static String anotherMethod() { return "Hello Again"; } } class ClassB { // legal ClassA instanceOfClassA = new ClassA(); String helloString = instanceOfClassA.aMethod(); // illegal String helloString = ClassA.aMethod(); // legal String halloAgainString = ClassA.anotherMethod(); } Why? Unless a method is declared static then it is only accessable through an instance of that class. If you want to use your getTotal() method, either declare it static, or create an instance of pSc and call it on that. Does this make sense?
Karis Brown
Ranch Hand
Joined: Nov 13, 2003
Posts: 33
posted
0
Kinda, I'm VERY new to this Java so an example would be nice please!
Karis Brown
Ranch Hand
Joined: Nov 13, 2003
Posts: 33
posted
0
LALALALLALALA! HAHAH!! :LOL! LMAO!! THANK YOU VERY MUCH!!! U GUYS ARE GREAT!!! Its working now!! Thanks again, thanks!! [ March 09, 2004: Message edited by: Karis Brown ] [ March 09, 2004: Message edited by: Karis Brown ]
Davy Kelly
Ranch Hand
Joined: Jan 12, 2004
Posts: 384
posted
0
well done Karis, Davy
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.