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!

i want it to draw, increment draw increment

It looks like the loop in the paintComponent() does what you want.
It does a page.fillRect() and then increments start and then does a page.fillRect() and then increments for values.length times.

What do you want to change?

yea the problem is, is that it looks as if it's doing it correctly, but it seems that when i run the program the first rectangle is actually starting where the last one should.

Debug the code by adding some println() statements to it to show the coordinates where the rect is being painted for each loop.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.