Guys im stuck once again.
I have a JList (unsorted) and when you press 'SORT' the list sorts.
The thing is i have to use bubble sort.
My jlist is set to defaultListModel.
My problem is i keep getting this error:
xception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to assignment2009.studentClass
I tried sorting the data by adding it to an arraylist then sorting but i was guided by my teacher by sorting direct from JList.
Any help on this one would be great, im a newbee to this, but 6 days trying to sort a list is crazy :)
Below is my sort method
and student class:
note: private DefaultListModel tranList = new DefaultListModel();
public void bubbleSort() {
studentClass tmp;
if (tranList.getSize() == 1) {
return;
}
for (int i = 0; i < tranList.getSize(); i++) {
for (int j = i + 1; j < tranList.getSize(); j++) {
if (((studentClass) tranList.get(i)).getStudentID() > ((studentClass) tranList.get(j)).getStudentID()) {
tmp = (studentClass) tranList.get(i);
tranList.set(i, tranList.get(j));
tranList.set(j, tmp);
}
}
}
}
package assignment2009;
public class studentClass
{
String studentName ;
int studentID;
String transType;
public int getStudentID()
{
return studentID;
}
public void setStudentID(int newStudentID)
{
this.studentID = newStudentID;
}
//--------------------------------------------------
public String getStudentName()
{
return studentName;
}
public void setStudentName(String newStudentName)
{
this.studentName = newStudentName;
}
//----------------------------------------------------
public String getTransType()
{
return transType;
}
public void setTransType(String newTransType)
{
this.transType = newTransType;
}
}
Thanks for trying