Sort.java

Go to the documentation of this file.
00001 
00012 package sorting;
00013 
00014 import java.awt.*;
00015 
00026 public abstract class Sort implements Runnable
00027 {
00028   protected long startTime = 0;
00029   protected long endTime = 0;
00030   protected long runTime = 0;
00031 
00032   protected int[] theArray;
00033   protected Panel thePanel;
00034   protected Label theLabel;
00035 
00041   public void run()
00042   {
00043     this.startTime = System.currentTimeMillis();
00044     doSort();   // call the sorting function - this function must be overloaded by child classes
00045     this.showArray();
00046     this.theLabel.setText(this.calcRuntime()+"ms - done!");
00047     this.theLabel.validate();
00048   }
00049 
00057   public int[] getSortedArray()
00058   {
00059     return this.theArray;
00060   }
00061 
00067   protected void doSort()
00068   {
00069   }
00070 
00071 
00079   protected void exchange(int[] aArray, int index1, int index2)
00080   {
00081     int tmp = aArray[index1];
00082     aArray[index1] = aArray[index2];
00083     aArray[index2] = tmp;
00084   }
00085 
00091   protected long calcRuntime()
00092   {
00093     return (System.currentTimeMillis()-startTime);
00094   }
00095 
00101   public void showArray()
00102   {
00103     Graphics g = thePanel.getGraphics();
00104     Color lc = new Color(0,255,0);
00105     Color bc = new Color(128,128,128);
00106     for (int i=0; i<210; i++)
00107     {
00108       g.setColor(lc);
00109       g.drawLine((i+20),190,(i+20),(190-theArray[i]));
00110       g.setColor(bc);
00111       g.drawLine((i+20),(190-theArray[i]),(i+20),10);
00112     }
00113     thePanel.validate();
00114   }
00115 
00123   public void setSettings(int[] aArray, Panel aPanel, Label aLabel)
00124   {
00125     this.theArray = aArray;
00126     this.thePanel = aPanel;
00127     this.theLabel = aLabel;
00128   }
00129   
00130 }
00131 

Generated on Thu Jun 22 19:07:31 2006 for Doxygen Example (Java) by  doxygen 1.4.5