import java.awt.*; import java.applet.*; public class bubble extends Applet implements Runnable { int stuff[] = new int[1000]; int a,b,c,q; boolean start=true; public void init(){ setBackground(Color.white); } public boolean mouseDown (Event e, int x, int y) { if(!start) start=true; return true; } public void start(){ Thread t = new Thread(this); t.start(); } public void paint(Graphics g){ for(a=0;a<100;a++){ g.setColor(Color.green); if(a==c+1 && start) g.setColor(Color.blue); if(a>99-b) g.setColor(Color.red); g.fillRect(0,a,stuff[a],1); } } public void run() { while(true){ if(start){ for(a=0;a<100;a++) stuff[a]=((int)(Math.random()*100))+1; for(b=0;b<99;b++){ for(c=0;c<99-b;c++){ if(stuff[c]>stuff[c+1]){ q=stuff[c]; stuff[c]=stuff[c+1]; stuff[c+1]=q; } repaint(); try{Thread.sleep(10);} catch(InterruptedException e){} } } start=false; repaint(); try{Thread.sleep(100);} catch(InterruptedException e){} } } } }