0

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.

speak
  • 5,202
  • 4
  • 36
  • 41

2 Answers2

2

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

Ray Toal
  • 86,166
  • 18
  • 182
  • 232
  • Would it be possible to create multiple replica forms if multiple results are found. I.E: I find 3 matching dates, 3 form windows appear displaying each result? – speak Jun 01 '12 at 13:47
  • 1
    Yes, simply add the new textfields to your jpanel (or whatever container you placed them in), and call `revalidate` or `repaint`. There are actually several SO questions with answers containing advice on how to do this, one is http://stackoverflow.com/questions/6516478/java-swing-dynamically-adding-components – Ray Toal Jun 01 '12 at 13:50
1

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).

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433