Results 1 to 7 of 7
  1. #1
    RamkumarP is offline Member
    Join Date
    Apr 2014
    Posts
    2
    Rep Power
    0

    Question How to pass values from one JFrame to another JFrame..?

    Am doing an application using JFrame, First step of the application is login page which I designed perfectly....
    When i click login button with right username and password it moves to another JFrame

    No i want pass "USERNAME" and "Database Credential" to the next JFrame....

    Can anyone Please help me....>

  2. #2
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    1

    Default Re: How to pass values from one JFrame to another JFrame..?

    Hi,

    there are multiple methods to do this. My approach is always to keep data in my own classes and do not mix up stuff. That way the GUI classes will have references to the instances that hold the data.

    In your case you could have a class UserDetails which holds the username and maybe information about it. The class could know how to verify that the password is correct. And both your Frames could have a reference to the same instance of that class.

    With kind regards,

    Konrad

  3. #3
    RamkumarP is offline Member
    Join Date
    Apr 2014
    Posts
    2
    Rep Power
    0

    Default Re: How to pass values from one JFrame to another JFrame..?

    Quote Originally Posted by kneitzel View Post
    Hi,

    there are multiple methods to do this. My approach is always to keep data in my own classes and do not mix up stuff. That way the GUI classes will have references to the instances that hold the data.

    In your case you could have a class UserDetails which holds the username and maybe information about it. The class could know how to verify that the password is correct. And both your Frames could have a reference to the same instance of that class.

    With kind regards,

    Konrad
    Can you please give an example because am new to JFrame...?

  4. #4
    SurfMan's Avatar
    SurfMan is online now Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    946
    Rep Power
    2

    Default Re: How to pass values from one JFrame to another JFrame..?

    There was exactly 16 minutes between Konrad's suggestion and your reply. Something tells me you haven't been experimenting with some code...
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  5. #5
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,984
    Rep Power
    5

    Default Re: How to pass values from one JFrame to another JFrame..?

    Quote Originally Posted by SurfMan View Post
    There was exactly 16 minutes between Konrad's suggestion and your reply. Something tells me you haven't been experimenting with some code...
    Or did any kind of research to become less "new to JFrame".
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    1

    Default Re: How to pass values from one JFrame to another JFrame..?

    It has nothing to do with JFrame - it is a generic object oriented approach.

    When creating an instance of a class, you get a reference to that instance back.
    This reference can be used in multiple placed. It is like an address. I can simply tell you the address and then you can go there and do something.

    Right now I have no idea how I could help you further.

    With kind regards,

    Konrad

  7. #7
    SurfMan's Avatar
    SurfMan is online now Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    946
    Rep Power
    2

    Default Re: How to pass values from one JFrame to another JFrame..?

    Here's a basic example. Both frames have access to the same user instance. Ofcourse you can make nice things like Singletons to accomplish the same.
    Java Code:
    public static void main(String[] args) {
        User blah = new User("foobar");
    
        MyFrame frame1 = new MyFrame();
        frame1.setUser(blah);
    
        MyFrame frame2 = new MyFrame();
        frame2.setUser(blah);
    
    }
    If I get a reply with an error message "Cannot resolve symbol setUser(User)" I am going to try and not cry alot.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Similar Threads

  1. Replies: 2
    Last Post: 12-08-2012, 09:05 AM
  2. pass data between jFrame objects and class in Java
    By sajjadbandari in forum New To Java
    Replies: 11
    Last Post: 09-08-2012, 11:11 PM
  3. pass data from Jdialog back to jFrame
    By Rogue45 in forum AWT / Swing
    Replies: 4
    Last Post: 04-05-2012, 12:35 AM
  4. Replies: 5
    Last Post: 06-14-2010, 06:10 PM
  5. Jframe pass variable to Applet
    By wayn in forum AWT / Swing
    Replies: 0
    Last Post: 03-10-2010, 09:54 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •