//seriously change it a little so teach doesent eat me
import java.awt.*;
import java.applet.*;
public class Lab15 extends Applet
{
private int numBars;
int barHeight[];
int sortDelay;
public void init()
{
numBars = 47;
sortDelay = 10;
barHeight = new int[numBars];
getBarValues();
}
public void getBarValues()
{
Expo.startSeed(3333);
for(int k = 0;k < numBars; k++)
{
barHeight[k] = Expo.seedRandom(10,600);
}
}
public void paint(Graphics g)
{
showFrame(g);
displayRandomBars(g);
clearRedBars(g);
sortBars(g);
}
public void showFrame(Graphics g)
{
g.fillRect(0,0,1300,20);
g.fillRect(0,0,20,1000);
g.fillRect(0,880,1000,20);
g.fillRect(980,0,20,880);
}
public void displayRandomBars(Graphics g)
{
g.setColor(Color.red);
for(int k = 0; (k+1) <= 47; k++)
{
g.fillRect(30+(k*20),barHeight[k],10,(880 - barHeight[k]));
}
}
public void sortBars(Graphics g)
{
int b;
g.setColor(Color.blue);
for(int k = 0; k < 47; k++)
{
Expo.delay(20);
for(int d = 0; d < 46; d++)
{
if(barHeight[d] < barHeight[d+1])
{
b = barHeight[d];
barHeight[d] = barHeight[d+1];
barHeight[d+1] = b;
}
g.fillRect(30+(k*20),barHeight[k],10,(880 - barHeight[k]));
}
}
}
public void clearRedBars(Graphics g)
{
g.setColor(Color.white);
for(int k = 0; (k+1) <= 47; k++)
{
Expo.delay(40);
g.fillRect(30+(k*20),barHeight[k],10,(880 - barHeight[k]));
}
}
}
No comments:
Post a Comment