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 9310691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:10:43+00:00 2026-06-19T01:10:43+00:00

I need to ask a small question because its irritating me. How do i

  • 0

I need to ask a small question because its irritating me.

How do i pass one vale from one frame to another frame in Java?

Below i have written a small script that is supposed to return the value but i dont quite know how to access it in the other frame.

Here is the code that is suppose to return the current value in a JcomboBox as a string into the other frame:

public String getUser(String user)

{

 user = (String)jComboBox1.getSelectedItem().toString();

return user;

}

The way i thought it would work is to call a new instance of that class into the other frame (the classes name is editUser) so here is what i thought i would need to do.

public editPass() 

{

initComponents();

editUser name = new editUser();

String test = name.getUser();

}

Thanks in advance for any advice.

  • 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-19T01:10:44+00:00Added an answer on June 19, 2026 at 1:10 am

    The problem is that with doing this: editUser name = new editUser() is that you are creating a new instance (besides the fact that class names should start with upper case as per convention). This causes you to loose any data since you are now referencing a new object.

    If you need to access data from the previous frame, what you would need to do would be to either:

    • Create a new object with all the relevant data and pass it to the next frame OR
    • Pass the current frame to the next frame. This will allow the new frame to be able to reference the previous one.

    As a side note, the Card Layout might be relevant to what you are trying to achieve.

    EDIT:
    As per your comment question:
    Assuming you have an editUser frame, say we call it frame1 and you populate all the data you need.
    Then, the user presses Next, or something similar which causes him/her to go to the next frame, thus frame1 will either be hidden or non existant any more, depending on your implementation.

    Let us call the second frame frame2. Now, in frame2 you need to access details stored in frame1. Doing like so: editUser name = new editUser(); will cause frame2 to create a new instance of frame1, thus meaning that you have created a new frame with empty values. Calling name.getUser() should not yield anything.

    When I mentioned create an object with the relevant data I meant that, if you are editing user values, you could create an object which would have for instance all the information which was edited. So it could have fields like userId, originalUserName, newUserName, etc.

    One the user presses Next in your frame1, you could create and populate this object and use it to transfer data from one frame to the next. In this case, the object you would be creating would be known as a Data Transfer Object (DTO).

    So, the constructor of your second frame would look something like so:

    public editPass(UserEditDTO userEditDTO)
    {
        initComponents();
        String test = userEditDTO.getNewUserName();  //gets the new username the user has provided.
    }
    

    And in your editUser class, just before creating a new instance of editPass, you would do something like so:

    ...
    UserEditDTO uEDTO = new UserEditDTO();
    uEDTO = ... //set all the relevant fields here
    new editPass(uEDTO).setVisible(true);
    ...
    

    Alternatively, you can pass a reference to frame1 instead of a DTO. This approach is simpler. So your constructor for editPass would look like this:

    public editPass(editUser editUser)
    {
        initComponents();
        String test = editUser.getUser();
    }
    

    With your editUser code looking like so:

    ...
    new editPass(this).setVisible(true);
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a beginner and i need to ask a question.. I wrote this small
I have a quite simple question to ask: I need to put a small
I have a SQL question that i need to ask the experts. To be
I know this sounds like a dumb question but I need to ask this.
Somebody ask me this question today . What is the need of reference in
I need create a document word with Java. And I ask, how can I
Dropping my lurker status to finally ask a question... I need to know how
I got a small question with a big background. Let me ask a short
There are numerous questions that ask in one way or another: How do I
One of my colleague asked me a question: "I want a small portion of

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.