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;
}

