一个可视化排序过程,为什么没效果呢,求高手谢谢....
package haha;
import java.awt.Color;
import java.awt.Graphics;
import haha.paint1.MyPanel;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class pain10 extends Thread {
static int []array=new int[]{80, 110, 130, 190, 175, 150, 140, 110, 220, 100, 70, 185};
static int n=12;
static JPanel pan = new MyPanel();
static paint1 frm = new paint1();
public void main(String[]args)
{
frm.setSize(300,250);
frm.add(pan);
pan.setBounds(100,100,300,250);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setVisible(true);
Thread k = new Thread(new pain10());
k.start();
}
public void paintComponent(Graphics g)
{
pan.paintComponents(g);
g.setColor(Color.red);
selection(array,n);
g.drawRect(500,(480-array[0]),20,array[0]);
g.drawRect(520,(480-array[1]),20,array[1]);
g.drawRect(540,(480-array[2]),20,array[2]);
g.drawRect(560,(480-array[3]),20,array[3]);
g.drawRect(580,(480-array[4]),20,array[4]);
g.drawRect(600,(480-array[5]),20,array[5]);
g.drawRect(620,(480-array[6]),20,array[6]);
g.drawRect(640,(480-array[7]),20,array[7]);
g.drawRect(660,(480-array[8]),20,array[8]);
g.drawRect(680,(480-array[9]),20,array[9]);
g.drawRect(700,(480-array[10]),20,array[10]);
g.drawRect(720,(480-array[11]),20,array[11]);
}
public void selection(int[]array,int n)
{
int smallIndex;
for(int i=0; i<n-1; i++)
{
smallIndex = i;
for(int j=i+1; j<n; j++)
{
if(array[j] < array[smallIndex])
{
smallIndex = j;
}
}
if(smallIndex != i)
{
int temp = array[i];
array[i] = array[smallIndex];
array[smallIndex] = temp;
}
run();
}
}
public void run()
{
try{
Thread.sleep(1000);
}
catch(InterruptedException e){}
}
}
------解决方案--------------------所有代码贴出来
------解决方案--------------------import haha.paint1.MyPanel; 这部分代码呢? paint1类代码贴出来下~