speak
speak

Reputation: 5382

Multiple Search Results, One GUI

I am searching through an array and matching the users entered date with ones stored in the array.

The code is working fine and finds dates or gives appropriate error messages perfectly, the only issue is due to the nature of my program it leaves the possibility of multiple records having the same date.

Now, I only have one form displaying each search result in this format:

lbl txtField lbl txtField

etc, if the date is matched, it will display the REST of the data matching the record in the text fields.

Now, how would it be possible to display every record's data that has matched a date?

My Code:

       public void searchDay() {
        String idInputString  = JOptionPane.showInputDialog(null, "Please enter the Date you're searching for using the format: DD/MM/YYYY");


        for (int i = 0, count = 0; i < orderID.length; i++) {
            if (idInputString.equals(startDate[i])) {

                txtOrderID.setText(orderID[i]);
                txtOrderForename.setText(customerForename[i]);
                txtOrderSurname.setText(customerSurname[i]);

                txtOrderAddress1.setText(address1[i]);
                txtOrderAddress2.setText(address2[i]);
                txtOrderTown.setText(town[i]);
                txtOrderCounty.setText(county[i]);
                txtOrderPost.setText(postCode[i]);
                txtOrderCarModel.setText(carModel[i]);

                txtOrderCarReg.setText(carReg[i]);
                txtOrderStartDate.setText(startDate[i]);
                txtOrderStartTime.setText(startTime[i]);

                txtOrderSerial.setText(serialNum[i]);
                count++;
            } 
            if(i == orderID.length - 1 && count==0){
                JOptionPane.showMessageDialog(null, "Order ID Doesn't Exist", "Error!", JOptionPane.WARNING_MESSAGE);
                break;
            }

   }
}

Thank you.

Upvotes: 0

Views: 444

Answers (2)

Andrew Thompson
Andrew Thompson

Reputation: 168825

The final UI could have a JList at the PAGE_START of the GUI that lists the orders for a day or range, but only displays the 'order number'. Then have a JPanel that contains a group of labels and field in the CENTER to display the details of an order selected in the list.

A JTable as suggested by @Ray might be a viable alternative, but I sometimes feel the data is more complex than can be well presented in a single table row (using one row per order).

Upvotes: 1

Ray Toal
Ray Toal

Reputation: 88378

Create more text fields on the fly, or drop results into a JTable.

Upvotes: 2

Related Questions