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();
	public void go(){
		GraphicsSortPanel t = new GraphicsSortPanel();
		JFrame frame = new JFrame("Graphics Sort");
		frame.setPreferredSize(new Dimension(700,300));
		GraphicsSort g = new GraphicsSort();
	public void selectionSort(Integer[] values){
		int min;
		int temp;
	//	timer = new Timer(DELAY);
		for(int index=0; index < values.length-1; index++){
	//	timer.start();
			for(int scan=index+1; scan <values.length;scan++)
				if(values[scan].compareTo(values[min]) <0)
					min = scan;
		//Swap the values
		temp = values[min];
	//	timer.stop();
        [B]public class GraphicsSortPanel extends JPanel{
		private final int SPACE=20, WIDTH=40;
		private int start=0;
		public void paintComponent(Graphics page){
			for(int i=0;i<values.length;i++){
				start+=SPACE + WIDTH;


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?

Edited 6 Years Ago by NormR1: n/a

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.

This article has been dead for over six months. Start a new discussion instead.