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