calling parent class methods from an extended subclass
Basically here is the gist of my problem: I've created a GUI thats a Calendar
to store to do list items for each day of the month. My main class, myCalendar,contains
a method called addItem. This method takes an object I've created(a to do
list Item) and stores it into a Vector. Later I call a method called printUnsorted(
from within the myCalendar class), which should access each element of the
Vector and then output the element to the screen. I have a subclass called
multiBox which extends from the myCalendar class. I extend it so that it
can access myCalendar's addItem method. Basically this subclass is declared
within myCalendar, then myCalendar sets it to visible after a day on the
calendar has been double clicked. multiBox is a frame, just like myCalendar
is. The user enters all the fields of an object( the to do list Item ) and
then clicks done. When done is clicked, multiBox calls myCalendar's addItem
with this new object as the passed in parameter. The problem here is this:
When inside multiBox I do get this object. I can output it and everything.
After I call addItem, and I'm inside addItem's body, the object is still
there. Then I add it to the Vector. I can than still access that item in
the Vector and output it to the screen so I know its still there, but when
myCalendar calls the printUnsorted method, and then prints out the Vector,
the Item is no longer there. In fact the Vector has a size of 0. I don't
know if it is because of the multiple frames, or how I'm making multiBox
a subclass of myCalendar, but I can't seem to get it to work. I would so
appreciate any help, and I can even send you the code if need be.
Thanks so much,
Nate
Re: calling parent class methods from an extended subclass
It sounds strange that you said multiBox extends myCalendar which means it's
a subclass, but you also said it's declared inside myCalendar which means
it's an inner class. It probably shouldn't be both. However, I don't think
this is causing the problem. I would have to see the code. printSorted()
sounds like it might be using a local variable of type Vector which has the
same name as the member variable of type Vector. That's just a problem that
I have had.
"Nate McFeters" <smoothnate@collegeclub.com> wrote:
>
>Basically here is the gist of my problem: I've created a GUI thats a Calendar
>to store to do list items for each day of the month. My main class, myCalendar,contains
>a method called addItem. This method takes an object I've created(a to
do
>list Item) and stores it into a Vector. Later I call a method called printUnsorted(
>from within the myCalendar class), which should access each element of the
>Vector and then output the element to the screen. I have a subclass called
>multiBox which extends from the myCalendar class. I extend it so that it
>can access myCalendar's addItem method. Basically this subclass is declared
>within myCalendar, then myCalendar sets it to visible after a day on the
>calendar has been double clicked. multiBox is a frame, just like myCalendar
>is. The user enters all the fields of an object( the to do list Item )
and
>then clicks done. When done is clicked, multiBox calls myCalendar's addItem
>with this new object as the passed in parameter. The problem here is this:
> When inside multiBox I do get this object. I can output it and everything.
> After I call addItem, and I'm inside addItem's body, the object is still
>there. Then I add it to the Vector. I can than still access that item
in
>the Vector and output it to the screen so I know its still there, but when
>myCalendar calls the printUnsorted method, and then prints out the Vector,
>the Item is no longer there. In fact the Vector has a size of 0. I don't
>know if it is because of the multiple frames, or how I'm making multiBox
>a subclass of myCalendar, but I can't seem to get it to work. I would so
>appreciate any help, and I can even send you the code if need be.
>
>Thanks so much,
>Nate
>