This application sorts one array . Want to represent the current item changed by a line equal value. I do not know where I would put the paint method (or draw) to draw my current item for the method "run ()" can not.
class sortareBubbleSort extends Canvas implements Runnable{
Dimension dim = new Dimension (300 , 300) ;
public Dimension getPreferredSize () {
return dim ;
}
public void paint ( Graphics g) {
g.setColor (Color.black);
g.drawRect (0, 0, dim .width -1, dim.height -1);
}
//public void update ( Graphics g) {
//paint (g);}
int nre,min,max;
public sortareBubbleSort(int nre,int min,int max){
this.nre=nre;
this.min=min;
this.max=max;
}
public void run(){
int[] x=new int [nre];
for(int i=0;i<x.length-1;i++)
x[i]=min+(int)(Math.random()*((max-min)+1));
boolean doMore = true;
while (doMore) {
doMore = false;
for (int i=0; i<x.length-1; i++) {
if (x[i] > x[i+1]) {
int temp = x[i];
x[i] = x[i+1];
x[i+1] = temp;
doMore = true;
g.drawLine(50,50,x[i+1],50);
}
}
}
}
In final I want it to look something like this:
for this array Arr[]={4,3,5,2,1} to draw in canvas :_ __ _ _ ____
( Arr sorted with one of sorted vector with one of methods)
1 2 3 4 5