Hey for some reason my rectangles are being drawn after the start variable has been incremented all the way through. This is causing them to go off the screen. What i wanted, is like in the code, i want it to draw, increment draw increment until the loop is finished.
import java.util.Scanner;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class GraphicsSort{
private Integer[] values={10,12,40,77,130,66,45,200,223,240};
private Timer timer;
private final int DELAY=100;
public static void main (String args[]) {
GraphicsSort g = new GraphicsSort();
g.go();
}
public void go(){
GraphicsSortPanel t = new GraphicsSortPanel();
JFrame frame = new JFrame("Graphics Sort");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setPreferredSize(new Dimension(700,300));
frame.getContentPane().add(t);
frame.pack();
frame.setResizable(false);
frame.setVisible(true);
GraphicsSort g = new GraphicsSort();
g.selectionSort(values);
}
public void selectionSort(Integer[] values){
int min;
int temp;
// timer = new Timer(DELAY);
for(int index=0; index < values.length-1; index++){
// timer.start();
min=index;
for(int scan=index+1; scan <values.length;scan++)
if(values[scan].compareTo(values[min]) <0)
min = scan;
//Swap the values
temp = values[min];
values[min]=values[index];
values[index]=temp;
}
// timer.stop();
}
[B]public class GraphicsSortPanel extends JPanel{
private final int SPACE=20, WIDTH=40;
private int start=0;
public void paintComponent(Graphics page){
super.paintComponent(page);
for(int i=0;i<values.length;i++){
page.fillRect(start,10,WIDTH,values[i]);
System.out.println("DRAWING");
start+=SPACE + WIDTH;
System.out.println(start);
}
}
}[/B]
}
Thanks for the help in advance!