求指导
import java.awt.Color;--------------------编程问答-------------------- 指导什么??????? --------------------编程问答--------------------
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.event.*;
public class paint2 extends JFrame implements ActionListener
{
static int[] array = new int[] { 80, 110, 130, 190, 175, 150, 140, 110,220, 100, 70, 185 };
static int n = 12;
static int H=0;
static JPanel pan = new JPanel();
static JButton bun1=new JButton("选择排序");
static JButton bun2=new JButton("堆排序");
static JButton bun3=new JButton("基排序");
static paint2 frm = new paint2();
public static void main(String[] args)
{
FlowLayout flow = new FlowLayout();
frm.setLayout(flow);
frm.add(bun1);
frm.add(bun2);
frm.add(bun3);
frm.add(pan);
frm.setSize(1800, 850);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setVisible(true);
bun1.addActionListener(frm);
bun2.addActionListener(frm);
bun3.addActionListener(frm);
}
public void actionPerformed(ActionEvent e){
JButton bt=(JButton)e.getSource();
if (bt==bun1) H=1;
else if (bt==bun2)H=2;
else if (bt==bun3)H=3;
paint1 p=new paint1();
Graphics g=p.getGraphics();
p.paint(g);
}
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.red);
if(H==1) selection(array,n);
else if (H==2)RadixSort(array,n);
else if (H==3)HeapSort(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;
}
}
}
public void RadixSort(int []array,int n)
{
}
public void HeapSort(int []array,int n)
{
}
}
估计是解析每一行给楼主 --------------------编程问答--------------------
不是吧?每一行解析?至少有个重点的吧?如果都不懂的话,先去学一下基础知识,从一些小程序开始
--------------------编程问答--------------------
难道楼主是散分来的?
补充:Java , Java SE