hey guys, im very new to java so bare with me...

i cant seem to bubble sort my arraylist...
The data needs to be displayed unsorted in a jlist, then when user clicks process the list is sorted according to student id.
If anyone could guide me through it would be great because ive been stuck on it for days....

i dont know how much code you need but im going to post all of it & if you need anymore details please let me know.

Thanks to anyone in advance...

package assignment2009;

import java.awt.event.MouseEvent;
import javax.swing.*;
import java.awt.event.MouseListener;
import java.util.*;



public class MainApplication extends javax.swing.JFrame implements   MouseListener {


    public MainApplication()
    {
        initComponents();
    tfJList.addMouseListener(this);

    }

    @SuppressWarnings("unchecked")

    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        top1Panel = new javax.swing.JPanel();
        clearTFButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tfJList = new javax.swing.JList();
        top2Panel = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        newMFile = new javax.swing.JList();
        infoBarButton = new javax.swing.JLabel();
        top3Panel = new javax.swing.JPanel();
        clearMFButton = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        mfJList = new javax.swing.JList();
        top4Panel = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        errorLog = new javax.swing.JTextArea();
        elLabel = new javax.swing.JLabel();
        botton1Panel = new javax.swing.JPanel();
        etButton = new javax.swing.JLabel();
        blank = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        nameSur = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        iD = new javax.swing.JTextField();
        previousButton = new javax.swing.JButton();
        nextRecord = new javax.swing.JButton();
        deleteButton = new javax.swing.JButton();
        addButton = new javax.swing.JButton();
        modifyButton = new javax.swing.JButton();
        defaultRecordsButton = new javax.swing.JButton();
        bottom2Panel = new javax.swing.JPanel();
        soLabel = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        demoSpeedSlider = new javax.swing.JSlider();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        singleShotCB = new javax.swing.JCheckBox();
        bottom3Panel = new javax.swing.JPanel();
        dcLabel = new javax.swing.JLabel();
        sDemoButton = new javax.swing.JButton();
        pDemoButton = new javax.swing.JButton();
        jToggleButton1 = new javax.swing.JToggleButton();
        bottom4Panel = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        helpTArea = new javax.swing.JTextArea();
        helpButton = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new java.awt.GridLayout(2, 5));

        top1Panel.setLayout(new java.awt.BorderLayout());

        clearTFButton.setText("Clear Transaction File");
        clearTFButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearTFButtonActionPerformed(evt);
            }
        });
        top1Panel.add(clearTFButton, java.awt.BorderLayout.PAGE_END);

        tfJList.setBackground(new java.awt.Color(0, 204, 255));
        tfJList.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2), "Transaction File", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Impact", 0, 13), new java.awt.Color(0, 0, 0))); // NOI18N
        tfJList.setModel(tranList);
        tfJList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(tfJList);

        top1Panel.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        getContentPane().add(top1Panel);

        top2Panel.setLayout(new java.awt.BorderLayout());

        newMFile.setBackground(new java.awt.Color(255, 51, 51));
        newMFile.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2), "New Master File", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Impact", 0, 13), new java.awt.Color(0, 0, 0))); // NOI18N
        newMFile.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane2.setViewportView(newMFile);

        top2Panel.add(jScrollPane2, java.awt.BorderLayout.CENTER);

        infoBarButton.setBackground(new java.awt.Color(102, 255, 51));
        infoBarButton.setFont(new java.awt.Font("Tahoma", 2, 14));
        infoBarButton.setForeground(new java.awt.Color(0, 51, 255));
        infoBarButton.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        infoBarButton.setText("Info Bar");
        infoBarButton.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 3, true));
        top2Panel.add(infoBarButton, java.awt.BorderLayout.PAGE_END);

        getContentPane().add(top2Panel);

        top3Panel.setLayout(new java.awt.BorderLayout());

        clearMFButton.setText("Clear Master File");
        clearMFButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearMFButtonActionPerformed(evt);
            }
        });
        top3Panel.add(clearMFButton, java.awt.BorderLayout.PAGE_END);

        mfJList.setBackground(new java.awt.Color(102, 255, 102));
        mfJList.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2), "Master File", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Impact", 0, 13), new java.awt.Color(0, 0, 0))); // NOI18N
        mfJList.setModel(masterList);
        mfJList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane3.setViewportView(mfJList);

        top3Panel.add(jScrollPane3, java.awt.BorderLayout.CENTER);

        getContentPane().add(top3Panel);

        top4Panel.setLayout(new java.awt.BorderLayout());

        errorLog.setBackground(new java.awt.Color(0, 102, 204));
        errorLog.setColumns(20);
        errorLog.setRows(5);
        jScrollPane4.setViewportView(errorLog);

        top4Panel.add(jScrollPane4, java.awt.BorderLayout.CENTER);

        elLabel.setFont(new java.awt.Font("Impact", 0, 13));
        elLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        elLabel.setText("Error Log");
        top4Panel.add(elLabel, java.awt.BorderLayout.PAGE_START);

        getContentPane().add(top4Panel);

        botton1Panel.setLayout(new java.awt.GridLayout(7, 2, 10, 10));

        etButton.setFont(new java.awt.Font("Impact", 0, 13));
        etButton.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        etButton.setText("Records");
        botton1Panel.add(etButton);
        botton1Panel.add(blank);

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel2.setText("Name / Surname:");
        botton1Panel.add(jLabel2);

        nameSur.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        nameSur.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nameSurActionPerformed(evt);
            }
        });
        botton1Panel.add(nameSur);

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel1.setText("ID Number:");
        botton1Panel.add(jLabel1);

        iD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                iDActionPerformed(evt);
            }
        });
        botton1Panel.add(iD);

        previousButton.setText("< Previous Record");
        previousButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        previousButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                previousButtonActionPerformed(evt);
            }
        });
        botton1Panel.add(previousButton);

        nextRecord.setText("Next Record >");
        nextRecord.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        nextRecord.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nextRecordActionPerformed(evt);
            }
        });
        botton1Panel.add(nextRecord);

        deleteButton.setText("Delete Record");
        deleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteButtonActionPerformed(evt);
            }
        });
        botton1Panel.add(deleteButton);

        addButton.setText("Add Record");
        addButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addButtonActionPerformed(evt);
            }
        });
        botton1Panel.add(addButton);

        modifyButton.setText("Modify Record");
        modifyButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                modifyButtonActionPerformed(evt);
            }
        });
        botton1Panel.add(modifyButton);

        defaultRecordsButton.setText("Load Default Records");
        defaultRecordsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                defaultRecordsButtonActionPerformed(evt);
            }
        });
        botton1Panel.add(defaultRecordsButton);

        getContentPane().add(botton1Panel);

        bottom2Panel.setLayout(new java.awt.GridLayout(7, 1, 10, 10));

        soLabel.setFont(new java.awt.Font("Impact", 0, 13));
        soLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        soLabel.setText("Simulation Options");
        bottom2Panel.add(soLabel);

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel4.setText("--- Automatic Simulation ---");
        bottom2Panel.add(jLabel4);

        demoSpeedSlider.setMaximum(10);
        demoSpeedSlider.setMinimum(1);
        demoSpeedSlider.setMinorTickSpacing(1);
        demoSpeedSlider.setPaintLabels(true);
        demoSpeedSlider.setPaintTicks(true);
        demoSpeedSlider.setSnapToTicks(true);
        demoSpeedSlider.setValue(5);
        bottom2Panel.add(demoSpeedSlider);

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setText("Slow                 Speed                      Fast");
        jLabel3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bottom2Panel.add(jLabel3);

        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel5.setText("--- Manual Simulation ---");
        bottom2Panel.add(jLabel5);

        singleShotCB.setText("Single Shot");
        singleShotCB.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        bottom2Panel.add(singleShotCB);

        getContentPane().add(bottom2Panel);

        bottom3Panel.setLayout(new java.awt.GridLayout(7, 1, 10, 10));

        dcLabel.setFont(new java.awt.Font("Impact", 0, 13));
        dcLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        dcLabel.setText("Demonstration Controls");
        bottom3Panel.add(dcLabel);

        sDemoButton.setText("Start Demonstration");
        sDemoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sDemoButtonActionPerformed(evt);
            }
        });
        bottom3Panel.add(sDemoButton);

        pDemoButton.setText("Pause");
        pDemoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pDemoButtonActionPerformed(evt);
            }
        });
        bottom3Panel.add(pDemoButton);

        jToggleButton1.setText("Next Step >");
        bottom3Panel.add(jToggleButton1);

        getContentPane().add(bottom3Panel);

        bottom4Panel.setLayout(new java.awt.BorderLayout());

        helpTArea.setBackground(new java.awt.Color(255, 255, 51));
        helpTArea.setColumns(20);
        helpTArea.setEditable(false);
        helpTArea.setFont(new java.awt.Font("Monospaced", 0, 12));
        helpTArea.setLineWrap(true);
        helpTArea.setRows(5);
        helpTArea.setText("Step 1\nAdd records to transaction file.\n\nStep 2\nSelect speed of demonstration or select single shot to process data in an instant.\n\nStep 3\nSelect Start Demonstation!");
        helpTArea.setWrapStyleWord(true);
        jScrollPane5.setViewportView(helpTArea);

        bottom4Panel.add(jScrollPane5, java.awt.BorderLayout.CENTER);

        helpButton.setFont(new java.awt.Font("Impact", 0, 13));
        helpButton.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        helpButton.setText("Help ");
        bottom4Panel.add(helpButton, java.awt.BorderLayout.PAGE_START);

        getContentPane().add(bottom4Panel);

        pack();
    }// </editor-fold>

    private void clearTFButtonActionPerformed(java.awt.event.ActionEvent evt) {                                              
        tranList.clear();
        infoBarButton.setText("Transaction File Cleared");
}                                             

    private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {                                          
    addRecord();
}                                         

    private void modifyButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
    modify();
}                                            

    private void defaultRecordsButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                     
    addDefaultData();       
}                                                    

    private void sDemoButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
    sort.bubbleSort(studTranArray );
}                                           

    private void pDemoButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
        // PAUSE
}                                           

    private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
    delete();
}                                            

    private void iDActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
}

    private void clearMFButtonActionPerformed(java.awt.event.ActionEvent evt) {                                              
    masterList.clear();
    infoBarButton.setText("Master File Cleared");
}                                             

    private void previousButtonActionPerformed(java.awt.event.ActionEvent evt) {                                               
    previousRecord();
}                                              

    private void nextRecordActionPerformed(java.awt.event.ActionEvent evt) {                                           
      System.out.println(studTranArray.size());
      nextRecord();
    }                                          

    private void nameSurActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
}

    
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainApplication().setVisible(true);


            }
        });
    }

 
     //javax.swing.tfJList=newList;
private DefaultListModel tranList = new DefaultListModel();
private DefaultListModel masterList = new DefaultListModel();
private DefaultListModel newMasterList = new DefaultListModel();
studentClass Nstudent = new studentClass();

//Default Transaction Array
ArrayList studTranArray = new ArrayList();
Vector studentVector = new Vector(studTranArray);

//Default Master File Array
List defNameMasterList = new ArrayList(); //Creates List Objects for default


//Default NewMaster File Array
List defNameNewMasterList = new ArrayList();

int nOrecords=0;
int index = 0;

      
    // Variables declaration - do not modify
    private javax.swing.JButton addButton;
    private javax.swing.JLabel blank;
    private javax.swing.JPanel bottom2Panel;
    private javax.swing.JPanel bottom3Panel;
    private javax.swing.JPanel bottom4Panel;
    private javax.swing.JPanel botton1Panel;
    private javax.swing.JButton clearMFButton;
    private javax.swing.JButton clearTFButton;
    private javax.swing.JLabel dcLabel;
    private javax.swing.JButton defaultRecordsButton;
    private javax.swing.JButton deleteButton;
    private javax.swing.JSlider demoSpeedSlider;
    private javax.swing.JLabel elLabel;
    private javax.swing.JTextArea errorLog;
    private javax.swing.JLabel etButton;
    private javax.swing.JLabel helpButton;
    private javax.swing.JTextArea helpTArea;
    private javax.swing.JTextField iD;
    private javax.swing.JLabel infoBarButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JToggleButton jToggleButton1;
    private javax.swing.JList mfJList;
    private javax.swing.JButton modifyButton;
    private javax.swing.JTextField nameSur;
    private javax.swing.JList newMFile;
    private javax.swing.JButton nextRecord;
    private javax.swing.JButton pDemoButton;
    private javax.swing.JButton previousButton;
    private javax.swing.JButton sDemoButton;
    private javax.swing.JCheckBox singleShotCB;
    private javax.swing.JLabel soLabel;
    private javax.swing.JList tfJList;
    private javax.swing.JPanel top1Panel;
    private javax.swing.JPanel top2Panel;
    private javax.swing.JPanel top3Panel;
    private javax.swing.JPanel top4Panel;
    // End of variables declaration
//-----------------------------------------------------------------
    public void addRecord()
    {
      studTranArray.add(iD.getText());
      studTranArray.add(nameSur.getText());

      tranList.addElement(nameSur.getText()+"     "+iD.getText());
      clear();
      infoBarButton.setText("Record Added To Transaction File!");
    }
//------------------------------------------------------------------
    public void clear()
    {
        nameSur.setText("");
        iD.setText("");

    }
//------------------------------------------------------------------
    public void addDefaultData()
    {
        String [] defaultNames = {"Alvin Du","Ryan Gosden","Michelle Dowling","Toni Dowling"};
        int [] defaultID = {153679,417950,234512,762903};


        for (int i=0;i<4;i++)
        {
            Nstudent.setStudentName(defaultNames[i]);
            Nstudent.setStudentID(defaultID[i]);

            studTranArray.add(Nstudent);

            tranList.addElement(defaultNames[i]+"     "+defaultID[i]); //adds arrays to JList
        }
             
         infoBarButton.setText("Default Records Loaded!");
         
    }
//------------------------------------------------------------------
    public void delete()
    {

     System.out.println(index);
        if (index ==0 || index<0)
           {
           JOptionPane.showMessageDialog(null,"No More Records To Delete");
           }
        else
           {
           tranList.remove(index);
           studTranArray.remove(index);
           }
    }

//------------------------------------------------------------------
    public void nextRecord()
    {
    int size =(studTranArray.size());

    if (nOrecords<size)
         {
         iD.setText(studTranArray.get(nOrecords).toString());
         nOrecords = nOrecords +1;
         }
    else
        {
         JOptionPane.showMessageDialog(null,"No More Records");
        }
    }
 //------------------------------------------------------------------
    public void previousRecord()
    {
    if(nOrecords>0)
        {
        nOrecords = nOrecords -1;
        iD.setText(studTranArray.get(nOrecords).toString());
        }
     else
        {
        JOptionPane.showMessageDialog(null,"No More Records");
        }
    }
//------------------------------------------------------------------
    public void modify()
    {
     tranList.remove(index);
     studTranArray.remove(index);
     studTranArray.add(iD.getText());
     tranList.addElement(iD.getText());
    }
//------------------------------------------------------------------
    //Sort Method!!!!!!
    public static void sort(ArrayList sortedList)
    {
 
            int count = 1;
            int size2 =(sortedList.size());

            for (int i = 0; i < size2; i++)
            {
                  System.out.print(sortedList.get(i) +" ");
            }
    
           
                  if (count % 10 == 0)
                  {
                        System.out.println();
                  }
                  count = count + 1;
            }
      
      static int bubbleSort(ArrayList <Integer> sortedList)
      {
            int count = 0;
            for (int outer = 0; outer < sortedList.size() - 1; outer++)
            {
                for (int inner = 0; inner < sortedList.size()-outer-1; inner++)
                {
                  if (sortedList.get(inner) > sortedList.get(inner + 1))
                  {
                    swapEm(sortedList, inner);
                    count = count + 1;
                  }
                }
              }
            return count;
      }
      static void swapEm(ArrayList<Integer>sortedList, int inner)
      {
            int temp = sortedList.get(inner);
            sortedList.set(inner, sortedList.get(inner + 1));
            sortedList.set(inner + 1, temp);
      }


//------------------------------------------------------------------
      public void mouseClicked(MouseEvent e)
          {

              JList tranList = (JList)e.getSource();
              if (e.getClickCount() == 1)
              {
               index = tranList.locationToIndex(e.getPoint());
               iD.setText(studTranArray.get(index).toString());
               nameSur.setText(studTranArray.get(index).toString());
               
               infoBarButton.setText("Item Selected");
              }
        }
         public void mouseEntered(MouseEvent e)
         {

         }
         public void mouseExited(MouseEvent e)
         {

        }
         public void mousePressed(MouseEvent e)
         {

         }
         public void mouseReleased(MouseEvent e)
         {

         }
}

Have look at this section from SCJP study guide

I tried Collections.sort but i get this error:

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: assignment2009.studentClass cannot be cast to java.lang.Comparable

The arraylist i want to sort (studTranArray) contains a string and an integer.
While the example only shows a string being sorted...
is there a way to select the variable type you want for sorting and the String will follow?

Can you post your updated code please, so we see what you tried and where can be problem?

Sorry about the code formatting. You have multiple things going on:

In "addDefaultData" you give the impression that "studTranArray" is a record.
Ok, records/struct don't really exist in Java so you can use a class to
try to achieve something similiar.

You do the following:

String [] defaultNames = {"Alvin Du","Ryan Gosden","Michelle Dowling","Toni Dowling"};
int [] defaultID = {153679,417950,234512,762903};

Nstudent.setStudentName(defaultNames);
Nstudent.setStudentID(defaultID);

studTranArray.add(Nstudent);


------------------------------------------------------------------------------
You declare "studTranArray" as follows:
ArrayList studTranArray = new ArrayList();

----------------------------------------------------

then in "addRecord", you do the following:
studTranArray.add(iD.getText());
studTranArray.add(nameSur.getText());

you are mixing what should probably be integer data (ID) with
String data (name). You need to keep your id's separate from
the names. Looks like you started to do this in "addDefaultData".
----------------------------------------------------
in "sDemoButtonActionPerformed" you call:
sort.bubbleSort(studTranArray );

but you declare "bubbleSort" as follows:

static int bubbleSort(ArrayList <Integer> sortedList)

------------------------------------------------------
Looks like you added "String" data to the array list and told
bubblesSort that you were going to pass it an "Integer" array list.

Even if you remove "<Integer>" from your bubbleSort declaration,
you can't compare String data with ">" or "<". You have to use
"compareTo" or "compareToIgnoreCase".

-------------------------------------------------------
I would recommend creating a separate class that separates the student data:


package assignment2009;

public class StudentClass {

        public StudentClass() {
    }


    protected String studentName;
    protected int studentID;



    public void setStudentName(String newStudentName)
     {
          this.studentName = newStudentName;
     }

     public String getStudentName()
     {
          return studentName;
     }

     public void setStudentID(int newStudentID)
     {
          this.studentID = newStudentID;
     }

     public int getStudentID()
     {
          return studentID;
     }

}

Then in the main application have something like the following:

package assignment2009;

	import java.util.ArrayList;
	import java.util.Vector;
	import javax.swing.JOptionPane;

   	public class MainApplication extends javax.swing.JFrame {


    	//create array list of type StudentClass
    	ArrayList<StudentClass> studTranArray = new ArrayList<StudentClass>();

    	//used to keep track of record number when pressing "previous" or "next"
    	int recordNumber = 0;

    	//used to keep track of how many array elements/students we have
   	 int recordCount = 0;



	//more code goes here

           //------------------------------------------------------------------
    	public void addDefaultData() {

		//may need to change some of the data around for testing
 		//"order by name" and "order by id" results in students being in the exact same order
                       
        		String[] defaultNames = {"Alvin Du", "Ryan Gosden", "Michelle Dowling", "Toni Dowling"};
        		int[] defaultID = {153679, 417950, 234512, 762903};

        		//clear array of any previous data
        		studTranArray.clear();

        		for (int i = 0; i < defaultNames.length; i++) {
            		recordCount = recordCount + 1;

            		//need to create new Nstudent for each loop
            		//otherwise all data will = the last student entered

            		StudentClass Nstudent = new StudentClass();

            		Nstudent.setStudentID(defaultID[i]);
            		Nstudent.setStudentName(defaultNames[i]);
            
            		studTranArray.add(Nstudent);
        		}

        		//displayData(studTranArray);
        		//statusLbl.setText("Default Records Loaded!");

   	 }

    	//------------------------------------------------------------------

    	private void bubbleSort(ArrayList<StudentClass> sortedList, String sortBy)
      	{
            	//start with the first element in the array
            	for (int outer = 0; outer < sortedList.size() - 1; outer++)
            	{
                		//compare "outer" element with rest of elements one by one
               		 //swap if necessary
                		for (int inner = outer+1; inner < sortedList.size(); inner++)
               	 	{
                    		//if sorting by id compare ids
                   		 if (sortBy.equalsIgnoreCase("id"))
                    		{
                       			 if (sortedList.get(outer).getStudentID() > sortedList.get(inner).getStudentID())
                        		{
                           			 statusLbl.setText("Swapping id:" + sortedList.get(inner).getStudentID() + 								" with " + sortedList.get(outer).getStudentID());
                            			
					swapEm(sortedList, outer, inner);
                            			//displayData(sortedList);
                        		}//end if
                   		 }
                    		else if(sortBy.equalsIgnoreCase("name"))
                    		{
                        		//use compareToIgnoreCase for String comparison
                       			 int result = sortedList.get(outer).getStudentName().compareToIgnoreCase							(sortedList.get(inner).getStudentName());

                        		//if "outer name" is alphabetically after "inner name" swap them
                        		if (result > 0)
                        		{
                            			statusLbl.setText("Swapping id:" + sortedList.get(inner).getStudentNam() 
							+ " with " + sortedList.get(outer).getStudentName());
                           
	 				swapEm(sortedList, outer, inner);
                            			//displayData(sortedList);
                        		}//end if
                     		}//end else if
                	}//end for
              }//end for
    }


      private void swapEm(ArrayList<StudentClass> sortedList, int outer, int inner)
      {

            StudentClass temp = sortedList.get(inner);
            sortedList.set(inner, sortedList.get(outer));
            sortedList.set(outer, temp);
      }

     }//end MainApplication

I tried Collections.sort but i get this error:

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: assignment2009.studentClass cannot be cast to java.lang.Comparable

The arraylist i want to sort (studTranArray) contains a string and an integer.
While the example only shows a string being sorted...
is there a way to select the variable type you want for sorting and the String will follow?

The runtime exception is thrown because the `sort' methods expects the ArrayList elements to implement the Comparable interface i.e. the class should have a method which logically compares students. If you can't change your class definition [for e.g. if your value objects or classes are automatically generated], you can use a variation of the `sort' method which accepts a custom Comparator.

// NULL checks and some other minor details omitted for brevity
class Student implements Comparable<Student> {
   
   private String name;
   
   private int id;
   
   public Student(String name, int id) {
      this.id = id;
      this.name = name;      
   }

   public String getName() {
      return this.name;
   }
   
   public int compareTo(Student student) {
      return this.id - student.id;
   }
   
   @Override
   public String toString() {
      return "{name:" + name + ",id:" + id + "}";
   }
   
}

public class ProxyTest {
   
   public static void main(final String[] args) {
      List<Student> list = new ArrayList<Student>();
      Student student = new Student("tom", 12);
      list.add(student);
      student = new Student("dick", 34);
      list.add(student);
      student = new Student("harry", 0);
      list.add(student);
      student = new Student("a sexy girl", -12);
      list.add(student);
      
      // Use the comparable nature of Student class when sorting i.e. sort by id
      Collections.sort(list);
      System.out.println(list);
      
      // Use a custom compare method which now sorts by name
      // Here we create an instance of anonymous class which implements the
      // Comarator interface. In case you need to re-use the same Comparator
      // at multiple places, create a proper class with the same code.
      Collections.sort(list, new Comparator<Student>() {
         public int compare(Student o1, Student o2) {
            return o1.getName().compareTo(o2.getName());
         }
      });
      System.out.println(list);
   }

}

[{name:a sexy girl,id:-12}, {name:harry,id:0}, {name:tom,id:12}, {name:dick,id:34}]
[{name:a sexy girl,id:-12}, {name:dick,id:34}, {name:harry,id:0}, {name:tom,id:12}]

As you can see, by crafting out well thought out compare methods, I've managed to keep "a sexy girl" ahead of others. :-)

It seems like i cant use Collections.sort because one of the main functionalities of this program is when the list gets sorted, the user has control over the speed of EACH record from arraylist being sorted into a new jlist....

Sorry if that sounds confusing...
here is an example

arraylist data unsorted on jlist A
George 34567
Peter 23456
Sam 12345

User now selects speed of items added to jlist (ie 5 seconds)

arraylist data sorted on jlist B
George 12345 (every 5 seconds a name enters the list)
Peter 23456
Sam 34567

So far i cant seem to get the bubblesort method in my add to system.out.println the sorted data.

Please post more information about the requirements for your program. Also more about how the data should look during different stages of the program execution as well as explanations as to why the data should look that way. It'd also be nice if you could show how the data is supposed to look (or how you think it looks) inside the arraylist (including data types).

Thanks cgeier & s.o.s for your help. I understand what your getting it and ill try out. its taking a bit of time to understand the full concept of OOP. Thanks for having patience...

hey cgeier, Ive added the student class and it seems to be working!
i still have a few small problems with the sorting though...

When the Object in the arrayList is sent to the parametre of bubblesort (which becomes sortedList) i think it sorts but i do not know how to 'refresh/display the jlist'.

Also if i do System.out.println(sortedList); i get the memory location and not the actual data stored in the array. im a little lost in how to display this data.

Im not sure if its right but ive changed the add record as follows:

From
studTranArray.add(iD.getText());
studTranArray.add(nameSur.getText());

To
studentClass Nstudent = new studentClass();
Nstudent.setStudentName(nameSur.getText());
Nstudent.setStudentName(iD.getText());

Now it is using the class i created...

i think im finally understanding something :) They only gave me 2 months to learn java and they want miracles :(

would you like me to post the updated code?

Ignore the last post! ive been playing around with the code and i finally got the Jlist updated with the sorted code!!
Thanks loads to everyone.
Im sure this wont be the last time you hear from me though! lol

thanks again

Hey Guys i came across another problem.

As i said before, the aim is to have 3 Jlists.
A Transaction Jlist
A Master JList
A New Master JList

The user will enter data into the transaction Jlist
There will already be default data in the Master JList
When the user preses process the data in the translist and master list sort and then become the new master jList.

the problem is the data inside newMasterList keeps gets some funny results...
its seemed like an easy part of the project, but i cant figure out whats wrong...

heres the code for a better look:

package assignment2009;

import java.awt.event.MouseEvent;
import javax.swing.*;
import java.awt.event.MouseListener;
import java.util.*;
import java.util.ArrayList;




public class MainApplication extends javax.swing.JFrame implements   MouseListener {


    public MainApplication()
    {
        initComponents();
    tfJList.addMouseListener(this);

    }

    @SuppressWarnings("unchecked")

    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        top1Panel = new javax.swing.JPanel();
        clearTFButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tfJList = new javax.swing.JList();
        top2Panel = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        newMList = new javax.swing.JList();
        statusLbl = new javax.swing.JLabel();
        top3Panel = new javax.swing.JPanel();
        clearMFButton = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        mfJList = new javax.swing.JList();
        top4Panel = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        errorLog = new javax.swing.JTextArea();
        elLabel = new javax.swing.JLabel();
        botton1Panel = new javax.swing.JPanel();
        etButton = new javax.swing.JLabel();
        blank = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        nameSur = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        iD = new javax.swing.JTextField();
        previousButton = new javax.swing.JButton();
        nextRecord = new javax.swing.JButton();
        deleteButton = new javax.swing.JButton();
        addButton = new javax.swing.JButton();
        modifyButton = new javax.swing.JButton();
        defaultRecordsButton = new javax.swing.JButton();
        bottom2Panel = new javax.swing.JPanel();
        soLabel = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        demoSpeedSlider = new javax.swing.JSlider();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        singleShotCB = new javax.swing.JCheckBox();
        bottom3Panel = new javax.swing.JPanel();
        dcLabel = new javax.swing.JLabel();
        sDemoButton = new javax.swing.JButton();
        pDemoButton = new javax.swing.JButton();
        jToggleButton1 = new javax.swing.JToggleButton();
        bottom4Panel = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        helpTArea = new javax.swing.JTextArea();
        helpButton = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new java.awt.GridLayout(2, 5));

        top1Panel.setLayout(new java.awt.BorderLayout());

        clearTFButton.setText("Clear Transaction File");
        clearTFButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearTFButtonActionPerformed(evt);
            }
        });
        top1Panel.add(clearTFButton, java.awt.BorderLayout.PAGE_END);

        tfJList.setBackground(new java.awt.Color(0, 204, 255));
        tfJList.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2), "Transaction File", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Impact", 0, 13), new java.awt.Color(0, 0, 0))); // NOI18N
        tfJList.setModel(tranList);
        tfJList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(tfJList);

        top1Panel.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        getContentPane().add(top1Panel);

        top2Panel.setLayout(new java.awt.BorderLayout());

        newMList.setBackground(new java.awt.Color(255, 51, 51));
        newMList.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2), "New Master File", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Impact", 0, 13), new java.awt.Color(0, 0, 0))); // NOI18N
        newMList.setModel(newMasterList);
        newMList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane2.setViewportView(newMList);

        top2Panel.add(jScrollPane2, java.awt.BorderLayout.CENTER);

        statusLbl.setBackground(new java.awt.Color(102, 255, 51));
        statusLbl.setFont(new java.awt.Font("Tahoma", 2, 14));
        statusLbl.setForeground(new java.awt.Color(0, 51, 255));
        statusLbl.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        statusLbl.setText("Info Bar");
        statusLbl.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 3, true));
        top2Panel.add(statusLbl, java.awt.BorderLayout.PAGE_END);

        getContentPane().add(top2Panel);

        top3Panel.setLayout(new java.awt.BorderLayout());

        clearMFButton.setText("Clear Master File");
        clearMFButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearMFButtonActionPerformed(evt);
            }
        });
        top3Panel.add(clearMFButton, java.awt.BorderLayout.PAGE_END);

        mfJList.setBackground(new java.awt.Color(102, 255, 102));
        mfJList.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2), "Master File", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Impact", 0, 13), new java.awt.Color(0, 0, 0))); // NOI18N
        mfJList.setModel(masterList);
        mfJList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane3.setViewportView(mfJList);

        top3Panel.add(jScrollPane3, java.awt.BorderLayout.CENTER);

        getContentPane().add(top3Panel);

        top4Panel.setLayout(new java.awt.BorderLayout());

        errorLog.setBackground(new java.awt.Color(0, 102, 204));
        errorLog.setColumns(20);
        errorLog.setRows(5);
        jScrollPane4.setViewportView(errorLog);

        top4Panel.add(jScrollPane4, java.awt.BorderLayout.CENTER);

        elLabel.setFont(new java.awt.Font("Impact", 0, 13));
        elLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        elLabel.setText("Error Log");
        top4Panel.add(elLabel, java.awt.BorderLayout.PAGE_START);

        getContentPane().add(top4Panel);

        botton1Panel.setLayout(new java.awt.GridLayout(7, 2, 10, 10));

        etButton.setFont(new java.awt.Font("Impact", 0, 13));
        etButton.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        etButton.setText("Records");
        botton1Panel.add(etButton);
        botton1Panel.add(blank);

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel2.setText("Name / Surname:");
        botton1Panel.add(jLabel2);

        nameSur.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        nameSur.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nameSurActionPerformed(evt);
            }
        });
        botton1Panel.add(nameSur);

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel1.setText("ID Number:");
        botton1Panel.add(jLabel1);

        iD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                iDActionPerformed(evt);
            }
        });
        botton1Panel.add(iD);

        previousButton.setText("< Previous Record");
        previousButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        previousButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                previousButtonActionPerformed(evt);
            }
        });
        botton1Panel.add(previousButton);

        nextRecord.setText("Next Record >");
        nextRecord.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        nextRecord.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nextRecordActionPerformed(evt);
            }
        });
        botton1Panel.add(nextRecord);

        deleteButton.setText("Delete Record");
        deleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteButtonActionPerformed(evt);
            }
        });
        botton1Panel.add(deleteButton);

        addButton.setText("Add Record");
        addButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addButtonActionPerformed(evt);
            }
        });
        botton1Panel.add(addButton);

        modifyButton.setText("Modify Record");
        modifyButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                modifyButtonActionPerformed(evt);
            }
        });
        botton1Panel.add(modifyButton);

        defaultRecordsButton.setText("Load Default Records");
        defaultRecordsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                defaultRecordsButtonActionPerformed(evt);
            }
        });
        botton1Panel.add(defaultRecordsButton);

        getContentPane().add(botton1Panel);

        bottom2Panel.setLayout(new java.awt.GridLayout(7, 1, 10, 10));

        soLabel.setFont(new java.awt.Font("Impact", 0, 13));
        soLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        soLabel.setText("Simulation Options");
        bottom2Panel.add(soLabel);

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel4.setText("--- Automatic Simulation ---");
        bottom2Panel.add(jLabel4);

        demoSpeedSlider.setMaximum(10);
        demoSpeedSlider.setMinimum(1);
        demoSpeedSlider.setMinorTickSpacing(1);
        demoSpeedSlider.setPaintLabels(true);
        demoSpeedSlider.setPaintTicks(true);
        demoSpeedSlider.setSnapToTicks(true);
        demoSpeedSlider.setValue(5);
        bottom2Panel.add(demoSpeedSlider);

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setText("Slow                 Speed                      Fast");
        jLabel3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bottom2Panel.add(jLabel3);

        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel5.setText("--- Manual Simulation ---");
        bottom2Panel.add(jLabel5);

        singleShotCB.setText("Single Shot");
        singleShotCB.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        bottom2Panel.add(singleShotCB);

        getContentPane().add(bottom2Panel);

        bottom3Panel.setLayout(new java.awt.GridLayout(7, 1, 10, 10));

        dcLabel.setFont(new java.awt.Font("Impact", 0, 13));
        dcLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        dcLabel.setText("Demonstration Controls");
        bottom3Panel.add(dcLabel);

        sDemoButton.setText("Start Demonstration");
        sDemoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sDemoButtonActionPerformed(evt);
            }
        });
        bottom3Panel.add(sDemoButton);

        pDemoButton.setText("Pause");
        pDemoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pDemoButtonActionPerformed(evt);
            }
        });
        bottom3Panel.add(pDemoButton);

        jToggleButton1.setText("Next Step >");
        bottom3Panel.add(jToggleButton1);

        getContentPane().add(bottom3Panel);

        bottom4Panel.setLayout(new java.awt.BorderLayout());

        helpTArea.setBackground(new java.awt.Color(255, 255, 51));
        helpTArea.setColumns(20);
        helpTArea.setEditable(false);
        helpTArea.setFont(new java.awt.Font("Monospaced", 0, 12));
        helpTArea.setLineWrap(true);
        helpTArea.setRows(5);
        helpTArea.setText("Step 1\nAdd records to transaction file.\n\nStep 2\nSelect speed of demonstration or select single shot to process data in an instant.\n\nStep 3\nSelect Start Demonstation!");
        helpTArea.setWrapStyleWord(true);
        jScrollPane5.setViewportView(helpTArea);

        bottom4Panel.add(jScrollPane5, java.awt.BorderLayout.CENTER);

        helpButton.setFont(new java.awt.Font("Impact", 0, 13));
        helpButton.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        helpButton.setText("Help ");
        bottom4Panel.add(helpButton, java.awt.BorderLayout.PAGE_START);

        getContentPane().add(bottom4Panel);

        pack();
    }// </editor-fold>

    private void clearTFButtonActionPerformed(java.awt.event.ActionEvent evt) {                                              
        tranList.clear();
        statusLbl.setText("Transaction File Cleared");
}                                             

    private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {                                          
    addRecord();
}                                         

    private void modifyButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
    modify();
}                                            

    private void defaultRecordsButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                     
    addTransactionDefaultData();
    addMasterDefaultData();
}                                                    

    private void sDemoButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            

studNewMasterArray.addAll(studTranArray);
studNewMasterArray.addAll(studMasterArray);
studTranArray.clear();
studMasterArray.clear();
tranList.clear();
masterList.clear();

bubbleSort(studNewMasterArray, sortArray);




}                                           

    private void pDemoButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
        // PAUSE
}                                           

    private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
    delete();
}                                            

    private void iDActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
}

    private void clearMFButtonActionPerformed(java.awt.event.ActionEvent evt) {                                              
    masterList.clear();
    statusLbl.setText("Master File Cleared");
}                                             

    private void previousButtonActionPerformed(java.awt.event.ActionEvent evt) {                                               
    previousRecord();
}                                              

    private void nextRecordActionPerformed(java.awt.event.ActionEvent evt) {                                           
      System.out.println(studTranArray.size());
      nextRecord();
    }                                          

    private void nameSurActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
}


    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainApplication().setVisible(true);


            }
        });
    }


     //javax.swing.tfJList=newList;
private DefaultListModel tranList = new DefaultListModel();
private DefaultListModel masterList = new DefaultListModel();
private DefaultListModel newMasterList = new DefaultListModel();
//studentClass Nstudent = new studentClass();

//Default Transaction Array
ArrayList<studentClass> studTranArray = new ArrayList<studentClass>(); //*
ArrayList<studentClass> studMasterArray = new ArrayList<studentClass>();
ArrayList<studentClass> studNewMasterArray = new ArrayList<studentClass>();
//Vector studentVector = new Vector(studTranArray);

//Default Master File Array
//ArrayList defNameMasterList = new ArrayList(); //Creates List Objects for default


//Default NewMaster File Array


int index=0;
int recordNumber = 0;
int recordCount = 0;
String sortArray = ("name");


    // Variables declaration - do not modify
    private javax.swing.JButton addButton;
    private javax.swing.JLabel blank;
    private javax.swing.JPanel bottom2Panel;
    private javax.swing.JPanel bottom3Panel;
    private javax.swing.JPanel bottom4Panel;
    private javax.swing.JPanel botton1Panel;
    private javax.swing.JButton clearMFButton;
    private javax.swing.JButton clearTFButton;
    private javax.swing.JLabel dcLabel;
    private javax.swing.JButton defaultRecordsButton;
    private javax.swing.JButton deleteButton;
    private javax.swing.JSlider demoSpeedSlider;
    private javax.swing.JLabel elLabel;
    private javax.swing.JTextArea errorLog;
    private javax.swing.JLabel etButton;
    private javax.swing.JLabel helpButton;
    private javax.swing.JTextArea helpTArea;
    private javax.swing.JTextField iD;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JToggleButton jToggleButton1;
    private javax.swing.JList mfJList;
    private javax.swing.JButton modifyButton;
    private javax.swing.JTextField nameSur;
    private javax.swing.JList newMList;
    private javax.swing.JButton nextRecord;
    private javax.swing.JButton pDemoButton;
    private javax.swing.JButton previousButton;
    private javax.swing.JButton sDemoButton;
    private javax.swing.JCheckBox singleShotCB;
    private javax.swing.JLabel soLabel;
    private javax.swing.JLabel statusLbl;
    private javax.swing.JList tfJList;
    private javax.swing.JPanel top1Panel;
    private javax.swing.JPanel top2Panel;
    private javax.swing.JPanel top3Panel;
    private javax.swing.JPanel top4Panel;
    // End of variables declaration
//-----------------------------------------------------------------
    public void addRecord()
    {
         studentClass Nstudent = new studentClass();


         Nstudent.setStudentName(nameSur.getText());
         Nstudent.setStudentName(iD.getText());

         studTranArray.add(Nstudent);
         tranList.addElement(nameSur.getText()+"     "+iD.getText());

         clear();
         statusLbl.setText("Record Added To Transaction File!");
    }
//------------------------------------------------------------------
    public void clear()
    {
        nameSur.setText("");
        iD.setText("");

    }
//------------------------------------------------------------------
    public void addTransactionDefaultData()
    {
        String [] defaultNames = {"Alvin Du","Ryan Gosden","Michelle Dowling","Toni Dowling"};
        int [] defaultID = {153679,417950,234512,762903};

        for (int i = 0; i < defaultNames.length; i++)
        {
          recordCount = recordCount + 1;


             studentClass Nstudent = new studentClass();

            Nstudent.setStudentName(defaultNames[i]);
            Nstudent.setStudentID(defaultID[i]);

            studTranArray.add(Nstudent);

            tranList.addElement(defaultNames[i]+"     "+defaultID[i]); //adds Object Array to JList


         statusLbl.setText("Default Records Loaded!");

        }
    }
//------------------------------------------------------------------

      public void addMasterDefaultData()
    {
        String [] defaultNames = {"Peter Smith","Paul Johnson","Amanda Fenech","Claire Borg"};
        int [] defaultID = {999999,876543,765789,654327};

        for (int i = 0; i < defaultNames.length; i++)
        {
          recordCount = recordCount + 1;


             studentClass Nstudent = new studentClass();

            Nstudent.setStudentName(defaultNames[i]);
            Nstudent.setStudentID(defaultID[i]);

            studMasterArray.add(Nstudent);

            masterList.addElement(defaultNames[i]+"     "+defaultID[i]); //adds Object Array to JList


         statusLbl.setText("Default Records Loaded!");

        }
    }
//--------------------------------------------------------------------------------
    public void delete()
    {

     System.out.println(index);
        if (index ==0 || index<0)
           {

           tranList.remove(index); //Deletes last record in feild the n displays msg.
           studTranArray.remove(index);
           JOptionPane.showMessageDialog(null,"No More Records To Delete");
           }
        else
           {
           tranList.remove(index);
           studTranArray.remove(index);
           }
    }

//------------------------------------------------------------------
    public void nextRecord()
    {
    int size =(studTranArray.size());

    if (index<size)
         {
         nameSur.setText(studTranArray.get(index).studentName);
         index = index +1;
         }
    else
        {
         JOptionPane.showMessageDialog(null,"No More Records");
        }
    }
 //------------------------------------------------------------------
    public void previousRecord()
    {
    if(index>0)
        {
        index = index -1;
        nameSur.setText(studTranArray.get(index).studentName);
        }
     else
        {
        JOptionPane.showMessageDialog(null,"No More Records");
        }
    }
     //System.out.println(sortedList.get(1).studentName);
//------------------------------------------------------------------
    public void modify()
    {
     tranList.remove(index);
     studTranArray.remove(index);

       studentClass Nstudent = new studentClass();

       Nstudent.setStudentName(nameSur.getText());
       Nstudent.setStudentName(iD.getText());

       studTranArray.add(Nstudent);
       tranList.addElement(nameSur.getText()+"     "+iD.getText());

         clear();
         statusLbl.setText("Record Modified!");


    }
//------------------------------------------------------------------

    private void bubbleSort(ArrayList<studentClass> sortedList, String sortBy)
        {
                //start with the first element in the array
                for (int outer = 0; outer < sortedList.size() - 1; outer++)
                {
                        //compare "outer" element with rest of elements one by one
                     //swap if necessary
                        for (int inner = outer+1; inner < sortedList.size(); inner++)
                    {
                            //if sorting by id compare ids
                         if (sortBy.equalsIgnoreCase("id"))
                            {
                                 if (sortedList.get(outer).getStudentID() > sortedList.get(inner).getStudentID())
                                {


                    swapEm(sortedList, outer, inner);
                                        //displayData(sortedList);
                                }//end if
                         }
                            else if(sortBy.equalsIgnoreCase("name"))
                            {
                                //use compareToIgnoreCase for String comparison
                                 int result = sortedList.get(outer).getStudentName().compareToIgnoreCase                            (sortedList.get(inner).getStudentName());

                                //if "outer name" is alphabetically after "inner name" swap them
                                if (result > 0)
                                {


                    swapEm(sortedList, outer, inner);
                                        //displayData(sortedList);
                                }//end if
                            }//end else if
                    }//end for
              }//end for
    }


      private void swapEm(ArrayList<studentClass> sortedList, int outer, int inner)
      {

            studentClass temp = sortedList.get(inner);
            sortedList.set(inner, sortedList.get(outer));
            sortedList.set(outer, temp);



            int size = sortedList.size();
            int i=0;



            while ( i <size)

            {
            newMasterList.addElement(sortedList.get(i).studentName +"     "+ sortedList.get(i).studentID);
            i++;
            }



      }




//------------------------------------------------------------------
      public void mouseClicked(MouseEvent e)
          {

              JList tranList = (JList)e.getSource();
              if (e.getClickCount() == 1)
              {
               index = tranList.locationToIndex(e.getPoint());

         //      iD.setText(studTranArray.get(index).studentID);

               nameSur.setText(studTranArray.get(index).studentName);

               statusLbl.setText("Item Selected");

                   //System.out.println(sortedList.get(1).studentName);
              }
        }
         public void mouseEntered(MouseEvent e)
         {

         }
         public void mouseExited(MouseEvent e)
         {

        }
         public void mousePressed(MouseEvent e)
         {

         }
         public void mouseReleased(MouseEvent e)
         {

         }
}

studentClass

package assignment2009;


public class studentClass
{

    String studentName ;
    int studentID;


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;
}
}

I can finally see the light at the end of the tunnel... now need more coffee. :)

Looks like you've made progress. There are many ways to accomplish a task. Here's something that may help. Use what you can for ideas. Sorry about the formatting.

import java.util.ArrayList;
import java.util.Vector;
import javax.swing.JOptionPane;

    //create array list of type StudentClass
    ArrayList<StudentClass> studMasterArray = new ArrayList<StudentClass>();

    ArrayList<StudentClass> studTransArray = new ArrayList<StudentClass>();

    //used to keep track of record number when pressing "previous" or "next"
    int recordNumber = 0;

    //used to keep track of how many array elements/students we have
    int recordCount = 0;

   //used to keep track of order
   String orderBy = "";

    public void addDefaultData() {
        String[] defaultNames = {"Alvin Du", "Ryan Gosden", "Michelle Dowling", "Toni Dowling", "Romeo Jones"};
        int[] defaultID = {153679, 417950, 234512, 762903, 200120};

        //clear array of any previous data
        studMasterArray.clear();
       

        for (int i = 0; i < defaultNames.length; i++) {
            recordCount = recordCount + 1;

            //need to create new Nstudent for each loop
            //otherwise all data will = the last student entered

            StudentClass Nstudent = new StudentClass();

            Nstudent.setStudentID(defaultID[i]);
            Nstudent.setStudentName(defaultNames[i]);

        
            studMasterArray.add(Nstudent);


           // tranList.addElement(defaultNames[i] + "     " + defaultID[i]); //adds arrays to JList
        }

        displayData(studMasterArray,masterJlist);
        
        statusLbl.setText("Default Records Loaded!");

    }

    //------------------------------------------------------------------

    public void orderRecordsByID(){
        statusLbl.setText("Sorting by id...");
        //set global variable value so we can keep track how newMasterJlist 
        //is ordered
        orderBy = "id";
 
        displayData(bubbleSort(studMasterArray,orderBy),newMasterJlist);
    }
    //------------------------------------------------------------------

    public void orderRecordsByName(){
        statusLbl.setText("Sorting by name...");
        //set global variable value so we can keep track how newMasterJlist 
        //is ordered
        orderBy = "name";

        displayData(bubbleSort(studMasterArray,orderBy),newMasterJlist);
    }
    //------------------------------------------------------------------
   

    private ArrayList<StudentClass> bubbleSort(ArrayList<StudentClass> arrayToSort, String sortBy)
      {
           //create a new arrayList to hold the sorted values
           ArrayList<StudentClass> sortedList = new ArrayList<StudentClass>();
         
           //copy all elements of ArrayList
         
           sortedList = (ArrayList)arrayToSort.clone();

            //start with the first element in the array
            for (int outer = 0; outer < sortedList.size() - 1; outer++)
            {
                //compare "outer" element with rest of elements one by one
                //swap if necessary
                for (int inner = outer+1; inner < sortedList.size(); inner++)
                {
                    //if sorting by id compare ids
                    if (sortBy.equalsIgnoreCase("id"))
                    {
                        if (sortedList.get(outer).getStudentID() > sortedList.get(inner).getStudentID())
                        {
                            swapEm(sortedList, outer, inner);
                        }//end if
                    }
                    else if(sortBy.equalsIgnoreCase("name"))
                    {
                        //use compareToIgnoreCase for String comparison
                        int result = sortedList.get(outer).getStudentName().compareToIgnoreCase(sortedList.get(inner).getStudentName());

                        //if "outer name" is alphabetically after "inner name" swap them
                        if (result > 0)
                        {
                            swapEm(sortedList, outer, inner);
               
                        }//end if
                     }//end else if
                }//end for
              }//end for
           
           return sortedList;
    }


      private void swapEm(ArrayList<StudentClass> sortedList, int outer, int inner)
      {

            StudentClass temp = sortedList.get(inner);
            sortedList.set(inner, sortedList.get(outer));
            sortedList.set(outer, temp);
      }


//------------------------------------------------------------------



    public void addRecord(){

            //create a variable of type StudentClass
            StudentClass Nstudent = new StudentClass();

            //set id and name
            Nstudent.setStudentID(Integer.parseInt(idTextBox.getText()));
            Nstudent.setStudentName(nameSurTextBox.getText());
            
            
            //add student to the arraylist
            studTransArray.add(Nstudent);
            studMasterArray.add(Nstudent);

            //update recordCount
            recordCount = recordCount + 1;
            statusLbl.setText("Record added. New count = " + recordCount);
            if (orderBy.equals(""))
            {
                //do nothing
                JOptionPane.showMessageDialog(null,"OrderBy is null.","Order By",JOptionPane.OK_OPTION);
            }
            else
            {
                //if masterJlist was previously sorted, then re-sort it
                studNewMasterArray = bubbleSort(studMasterArray,orderBy);
                displayData(bubbleSort(studMasterArray,orderBy),newMasterJlist);
            }
            
            displayData(studMasterArray,masterJlist);
            displayData(studTransArray,transJlist,"added.");
    }

   //------------------------------------------------------------------

        public void modifyRecord(){

            //create a variable of type StudentClass
            StudentClass Nstudent = new StudentClass();

            //set id and name
            Nstudent.setStudentID(Integer.parseInt(idTextBox.getText()));
            Nstudent.setStudentName(nameSurTextBox.getText());

            //add student to the arraylist
            studMasterArray.set(recordNumber, Nstudent);

            //copy the record information to the transaction list before modification
            studTransArray.add(studMasterArray.get(recordNumber));
            displayData(studMasterArray,transJlist,"modified.");


            statusLbl.setText("Record modified.");

            if (orderBy.equals(""))
            {
                //do nothing
            }
            else
            {
                //if masterJlist was previously sorted, then re-sort it
                studNewMasterArray = bubbleSort(studMasterArray,orderBy);
                displayData(studNewMasterArray,newMasterJlist);
            }
        
    }

   //------------------------------------------------------------------
       public void deleteRecord(){

            //needed to prevent IndexOutOfBoundsException
            //can't retrieve a name when no records exist
            if (studMasterArray.size() >0){
                //confirm deleting the record
                int result = JOptionPane.showConfirmDialog(this,"Delete '" + studMasterArray.get(recordNumber).getStudentName() + "'?","Confirm",JOptionPane.OK_CANCEL_OPTION);
                statusLbl.setText(Integer.toString(result));

                //when ok is pressed result = 0; cancel = 2
                if (result == 0){
                    //copy the record information to the transaction list before deleting
                    studTransArray.add(studMasterArray.get(recordNumber));
                    //delete the record from the master list
                    studMasterArray.remove(recordNumber);
                    recordCount = recordCount - 1;
                    recordNumber = 0;
                    statusLbl.setText("Record deleted. New count = " + recordCount);
                    displayData(studTransArray,transJlist,"deleted.");

                    if (orderBy.equals(""))
                    {
                        //do nothing
                    }
                    else
                    {
                        //if masterJlist was previously sorted, then re-sort it
                        studNewMasterArray = bubbleSort(studMasterArray,orderBy);
                        displayData(studNewMasterArray,newMasterJlist);
                    }
                }
            }
            else{
                //notify user that no records exist
                JOptionPane.showMessageDialog(null,"No records exist.","No records",JOptionPane.OK_OPTION);
            }
            displayData(studMasterArray,masterJlist);

    }

   //------------------------------------------------------------------

   public void getAndShowPreviousRecord(){
        if (recordCount != 0){
            //if we are at the beginning of the arraylist and press "previous"
            //go to the last element in the arraylist
            if(recordNumber == 0){
                recordNumber = studMasterArray.size()-1;
            }
            else{
                recordNumber = recordNumber - 1;
            }
        }
        else{
               statusLbl.setText("There is only 1 record currently.");
        }

        statusLbl.setText("Record number " + recordNumber);

        //Need to convert integer to string to display in textbox
        idTextBox.setText(Integer.toString(studMasterArray.get(recordNumber).getStudentID()));
        nameSurTextBox.setText(studMasterArray.get(recordNumber).getStudentName());

    }

   //------------------------------------------------------------------
    public void getAndShowNextRecord(){

        if (recordCount != 0){

            if(recordNumber < studMasterArray.size()-1){
                recordNumber = recordNumber + 1;
            }
            else{
                //if we are at the end of the arraylist and press "next"
                //go to the first element in the arraylist
                recordNumber = 0;
            }
        }
        else{
               statusLbl.setText("There is only 1 record currently.");
        }

        statusLbl.setText("Record number " + recordNumber);

        //Need to convert integer to string to display in textbox
        idTextBox.setText(Integer.toString(studMasterArray.get(recordNumber).getStudentID()));
        nameSurTextBox.setText(studMasterArray.get(recordNumber).getStudentName());

    }
   //------------------------------------------------------------------

    private void displayData(ArrayList<StudentClass> myArrayList, javax.swing.JList myList){
        String userData = "";

        //needed for jList
        Vector studentData = new Vector();

        //clear the jList box
        myList.clearSelection();


        //add student data to vector
        for (int i=0; i<myArrayList.size();i++){
            studentData.add(myArrayList.get(i).getStudentID() + " " + myArrayList.get(i).getStudentName());
        }

        //needed if all records are deleted
        statusLbl.setText("Size: " + Integer.toString(myArrayList.size()));

        //if data exists add to jList, otherwise just leave it empty
        if (myArrayList.size() >0){
            myList.setListData(studentData);
            
            //cast student id which is an int to a String for text box
            idTextBox.setText(Integer.toString(studMasterArray.get(recordNumber).getStudentID()));
            nameSurTextBox.setText(studMasterArray.get(recordNumber).getStudentName());
        }
        else
        {
            //no records exist; blank out text boxes
            JOptionPane.showMessageDialog(null,"No records exist (" + myArrayList.size() + ")","No Records",JOptionPane.OK_OPTION);
            idTextBox.setText("");
            nameSurTextBox.setText("");
        }


        
    }

    //overloaded to allow a comment to be added
    private void displayData(ArrayList<StudentClass> myArrayList, javax.swing.JList myList, String myComment){
        String userData = "";

        //needed for jList
        Vector studentData = new Vector();

        //clear the jList box
        myList.clearSelection();


        //add student data to vector
        for (int i=0; i<myArrayList.size();i++){
            studentData.add(myArrayList.get(i).getStudentID() + " " + myArrayList.get(i).getStudentName() + " " + myComment);
        }

        //needed if all records are deleted
        statusLbl.setText("Size: " + Integer.toString(myArrayList.size()));

        //if data exists add to jList, otherwise just leave it empty
        if (myArrayList.size() >0){
            myList.setListData(studentData);

            //cast student id which is an int to a String for text box
            idTextBox.setText(Integer.toString(studMasterArray.get(recordNumber).getStudentID()));
            nameSurTextBox.setText(studMasterArray.get(recordNumber).getStudentName());
        }
        else
        {
            //no records exist; blank out text boxes
            idTextBox.setText("");
            nameSurTextBox.setText("");
        }



    }

Wow, thanks cgeier. I just sorted my sortmethod out (at last). I dropped using arraylists and sorted direct from Jlist, i will study the way you sorted the program as it seems great... I need to add some user display msgs, and with thiis post uve given me soe great ideas.
Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.