Outputting sorted array on the fly. Need a little help

For part of my final I have to right a program that sorts and displays an array of 10 integers ascending on the fly as the user inputs them. I've used several sort methods, but no matter what I try I can't get the first 5 indexes to print. I can get them to print descending but not ascending?

import javax.swing.*;

import BreezySwing.*;

import java.awt.SystemColor;

import java.awt.Color;

publicclass ArraySortextends GBFrame{

//Declare window objects

private JLabelenterLabel;

private IntegerField inputField;

private JButtonclearButton;

private JButtonenterButton;

private JTextAreaoutput;

//Declare other instance variables

privateint count;

privateint aryCount;

privateint[] ary =newint[10];

//Constructor

public ArraySort(){

//Initialize data

count = 0;

aryCount = 0;

//Instantiate window objects

enterLabel = addLabel("Enter integers here:" ,1,1,1,1);

inputField = addIntegerField (0,1,2,1,1);

clearButton = addButton("Clear" ,2,1,1,1);

enterButton = addButton("Enter" ,2,2,1,1);

output= addTextArea("",3,1,3,3);

//Disable text area, set focus to input

output.setEnabled(false);

inputField.requestFocus();

inputField.setText("");

try{

jbInit();

}

catch (Exception ex){

ex.printStackTrace();

}

}

//ButtonClicked method

publicvoid buttonClicked (JButton buttonObj){

//Clear output area and reset variables

if (buttonObj == clearButton){

inputField.requestFocus();

inputField.setText("");

output.setText("");

ary =newint[10];

count = 0;

aryCount = 0;

enterButton.setEnabled(true);

}

elseif (buttonObj == enterButton){

count += 1;

ary[aryCount] = inputField.getNumber();

aryCount += 1;

if (ary.length < 1)

output.append("\n" +"Here are your sorted numbers:" +"\n" +

ary[1]);

else{

bubbleSort(ary);

fill();

}

//Clear and give focus to input field after each input for ease of use

inputField.setText("");

inputField.requestFocus();

//Output unsorted and sorted array when array is full

if (count == 10){

enterButton.setEnabled(false);

}

}

}

//Fill method

privatevoid fill(){

output.append("\n" +"Here are your sorted numbers:" +"\n");

for (int i = 0; i < count; i++){

output.append(ary[i] +" ");

}

}

publicstaticvoid bubbleSort(int[] a){

int k = 0;

boolean exchangeMade =true;

//Make up to n - 1 passes through array, exit early if no exchanges

//are made on previous pass

while ((k < a.length) && exchangeMade){

exchangeMade =false;

k++;

for (int j = 0; j < a.length - k; j++)

if (a[j] > a[j + 1]){

swap(a, j, j + 1);

exchangeMade =true;

}

}

}

//Helper method for bubblesort

publicstaticvoid swap(int[] a,int x,int y){

int temp = a[x];

a[x] = a[y];

a[y] = temp;

}

[6784 byte] By [madDoga] at [2007-11-27 3:01:04]
# 1
http://java.sun.com/javase/6/docs/api/Arrays.sort(ary);for (int i = 0; i < ary.length; i++) {System.out.println(ary[i]);}
kmangolda at 2007-7-12 3:42:45 > top of Java-index,Java Essentials,New To Java...
# 2
This is in a GUI so System.out won't work. Also I get the message "cannot find symbol; symbol :variable Arrays, location: class ArraySort" when I try to use Arrays.sort?
madDoga at 2007-7-12 3:42:45 > top of Java-index,Java Essentials,New To Java...
# 3

This is what the output looks like now:

Here are your sorted numbers:

0

Here are your sorted numbers:

0 0

Here are your sorted numbers:

0 0 0

Here are your sorted numbers:

0 0 0 0

Here are your sorted numbers:

0 0 0 0 0

Here are your sorted numbers:

0 0 0 0 0 5

Here are your sorted numbers:

0 0 0 0 0 4 5

Here are your sorted numbers:

0 0 0 0 0 3 4 5

Here are your sorted numbers:

0 0 0 0 0 2 3 4 5

Here are your sorted numbers:

0 0 0 0 0 1 2 3 4 5

when I input 10Enter 9Enter...1Enter.

But the first output should be:

Here are your sorted numbers:

10

...

...

And the last should be:

Here are your sorted numbers:

1 2 3 4 5 6 7 8 9 10

madDoga at 2007-7-12 3:42:45 > top of Java-index,Java Essentials,New To Java...
# 4

Some clarification needed. Are you trying to

1. Print out the numbers in order but afterwards the list is still in original unsorted order

2. Sort the list and then print it out afterwards

3. Sort and print the sorted sublist at the same time. eg list is

5 3 1 2 4

1 3 5 2 4 and 1 is printed

1 2 5 3 4 and 1 2 is printed etc

floundera at 2007-7-12 3:42:45 > top of Java-index,Java Essentials,New To Java...
# 5
Sort and print as they are entered:10 is entered:10 is printed7 is entered:7 10 is printed3 is entered:3 7 10 is printed etc., until the array of 10 integers is full.
madDoga at 2007-7-12 3:42:45 > top of Java-index,Java Essentials,New To Java...
# 6

Sort and print as they are entered:

10 is entered:(ary[0])

10 is printed

7 is entered:(ary[1])

7 10 is printed

3 is entered:(ary[2])

3 7 10 is printed etc., until the array of 10 integers is full.

...

...

89 is entered(ary[9])

1 2 3 3 4 7 10 45 77 89(the entire array) is printed.

madDoga at 2007-7-12 3:42:45 > top of Java-index,Java Essentials,New To Java...
# 7

Right, so when you sort the array all the 0's (which are the default values for unused elements of the array) are sorted to the front (if you only have positive numbers. Therefore you must be trying to sort the entire array. Just sort the array of how many numbers entered so far. eg

10 entered, array: 10 0 0 0 0 0 0 0 0 0 - no need to sort just print arr[0]

7 entered, array: 10 7 0 0 0 0 0 0 0 0, sort only the first two numbers

array: 7 10 0 0 0 0 0 0 0 0

You must have a variable keeping track of where to insert the next number into the array. So when you do your sort and print, only go as far as that number not array.length.

floundera at 2007-7-12 3:42:45 > top of Java-index,Java Essentials,New To Java...
# 8
Thanks flounder! I had to change the public static void to a private void, but it did the trick!
madDoga at 2007-7-12 3:42:45 > top of Java-index,Java Essentials,New To Java...