Note that there are some explanatory texts on larger screens.

plurals
  1. POCollecting data from various different JFrames efficiently
    primarykey
    data
    text
    <p>Consider the following scenario:</p> <p>I have a JFrame "<strong>Main</strong>" which has a jButton "<strong>caravanDataButton</strong>" which opens another JFrame "<strong>CaravanData</strong>".</p> <p><strong>CaravanData</strong> has several JTextFields. Its purpose is to ask the user questions and transfer the answers back to <strong>Main</strong> once the user has completed.</p> <p>My question: <strong>What is the most efficient way of transferring data from a child JFrame to a calling parent JFrame (Or from this example from CaravanData back to Main)</strong></p> <p>Ideally I would like to do the following:<br/></p> <pre><code>class Main { public Main { CustomVariable data = new CaravanData(); } } </code></pre> <p>However, a constructor doesn't have a return type. But this would be the best way because the variable "data" wouldn't be assigned a value until the class <strong>CaravanData</strong> had finished its business.<br/></p> <p>My alternative solution is to use getters and setters. But I have to wait until the user has completed the form before I retrieve the data. I used a while loop:</p> <pre><code>class Main { public Main { CaravanData caravanData = new CaravanData(); while (caravanData.isUserFinished == false) {//...Do nothing} // Once the user has finished - collect the data: CustomVariable data = caravanData.getRelevantData(); } } class CaravanData { ... public boolean isUserFinished() {return ifUserHasCompletedForm;} public CustomerVariable getRelevantData() { ... return data; } } </code></pre> <p>I don't think this method is efficient at all. Is there a better technique? I have a few JFrames because there are a lot of question to be asked. I wasn't sure how to word this to find answers on the net. I did think of using threads? Stopping one process until the other finishes. But I was under the impression you only use threads when a task consumes to much time from the EDT?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload