Help with abstract classes and getting data from a JList
Author |
Message |
Bo0sT
|
Posted: Wed Apr 01, 2009 12:51 am Post subject: Help with abstract classes and getting data from a JList |
|
|
*So my initial problem is that I want to have a JList in my Swing app. I want to have info from the JList returned to my program so that I can save it to a file or display it in other parts of my swing app. From asking around, it seems to best and maybe the only way to do this is by subclassing an abstract class. 'Subclassing an abstract class' totally new topic for me, so I start looking around the web, trying to find info. I finally think i've got somewhat of a basic understanding of it, still a few blanks but please tell me where i'm wrong.
So basically an abstract class is an interface with less restrictions. You don't implement it like an interface though, and you can't make an instance of it, the only way to create an object of it is to create a subclass of it, a new class that extends it. Once you've done that, you need to override all abstract methods in the subclass, other than the ones that are already implemented in the abstract class itself. You can now make an object of this subclass and call the implemented methods.
...Ok so that is my understanding of how abstract methods work, now my attempt at using it
code: |
class NavListModel extends AbstractListModel
{
public Object getElementAt(int index)
{
return "";
}
public int getSize()
{
return 0;
}
}
|
Ok so there is my code for the subclass, now how do I make getElementAt return an object representing the data at element number 'index'? And how do I make getSize return the size of my list?
Please answer my questions and correct w/e is wrong on my understanding of abstract classes and methods, much appreciated. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
wtd
|
Posted: Wed Apr 01, 2009 1:17 am Post subject: RE:Help with abstract classes and getting data from a JList |
|
|
Your NavListModel will have to have a JList field to reference? |
|
|
|
|
|
Bo0sT
|
Posted: Wed Apr 01, 2009 1:22 am Post subject: Re: Help with abstract classes and getting data from a JList |
|
|
oh is that how it works? well can you please show me how to do that with a sample JList, tyvm |
|
|
|
|
|
Bo0sT
|
Posted: Wed Apr 01, 2009 2:10 am Post subject: Re: Help with abstract classes and getting data from a JList |
|
|
ooooooooo i just got it, i understand now, tyvm for ur help, i realised what i was doing wrong |
|
|
|
|
|
|
|