Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8977569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:24:06+00:00 2026-06-15T19:24:06+00:00

Consider the following scenario: I have a JFrame Main which has a jButton caravanDataButton

  • 0

Consider the following scenario:

I have a JFrame “Main” which has a jButton “caravanDataButton” which opens another JFrame “CaravanData“.

CaravanData has several JTextFields. Its purpose is to ask the user questions and transfer the answers back to Main once the user has completed.

My question: 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)

Ideally I would like to do the following:

class Main
{
    public Main
    {
        CustomVariable data = new CaravanData();
    }
}

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 CaravanData had finished its business.

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:

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

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:24:08+00:00Added an answer on June 15, 2026 at 7:24 pm

    Try to use a JDialog as your child Window. The setVisible(true) method of JDialog blocks till the dialog is disposed (usually by calling setVisible(false) from inside the dialog)

    After that you can load all data by your getRelevantData() method.

     class Main
     {
         public Main
         {
             CaravanData caravanData = new CaravanData();
             // Show the dialog - setVisible(true) blocks till ok is pressed
             caravanData.setVisible(true);
    
             // Once the user has finished - collect the data:
             CustomVariable data = caravanData.getRelevantData();
         }
     }
    
    class CaravanData extends JDialog
    {
        ...
        // Called by an ActionListener for the OK Button
        private void okButtonPressed(){
             setVisible(false);
        }
    
        public CustomerVariable getRelevantData()
        {
           ...
           return data;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following scenario. I have a method which returns ISomething , but it
Consider following scenario: I have RESTful URL /articles that returns list of articles user
Consider the following scenario We have a simple database that involves two entities: user
Consider the following scenario . I have an array of numbers: [ 1,2,3,4 ]
From couple of days i am thinking of a following scenario Consider I have
I have a question regarding a race condition scenario. The question: Consider the following
Let's consider the following scenario: a function which can generate code colors from white
Consider the following scenario. We have a C++ function with a static local variable:
Let's consider the following scenario. I have the following page where all rendered elements
consider the following scenario: I have a storyboard-based app. I add a ViewController object

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.