Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: using objects from one jFrame on a different jFrame

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    2
    My Mood
    Worried
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation using objects from one jFrame on a different jFrame

    hi

    I have to forms, A login form and a main form. The login form has a username, password and a combo box and a combo box that allows you to choose the type of user (cashier, supervisor and administrator). My login form works, but i want to know how i can use the selected item from the combo box in the main form. can anyone explain to me how to do this? i just started learning java this year and am struggling with this question. Below i attached a picture of the login form: Please help me
    loginform.jpg


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: using objects from one jFrame on a different jFrame

    You have to pass the values as parameters into setter functions in your "main form" class, or you have to return them in getter functions in your "login form" class. This will require you to have access to one class from the other.

    Or you could use a dialog.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    2
    My Mood
    Worried
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: using objects from one jFrame on a different jFrame

    i created a constructor in the login form to determine what kind of user was selected, but it is only returning 0. The constructor is like this:

    public class loggedInAs {

    int logo;

    loggedInAs (){
    logo = cmbLogin.getSelectedIndex();
    }
    int whousing (){

    return logo;

    }

    }

    and i am calling it in the main frame like this:


    loggedInAs user = new loggedInAs();
    personloggedon = user.whousing();

    why is the index of the selected item not changing?

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: using objects from one jFrame on a different jFrame

    If you want help, you'll have to provide an SSCCE (the smaller, the better) that demonstrates the problem.

    I also strongly suggest you follow the standard naming conventions- classes start with a capital letter, variables and methods with a lowercase letter.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. connecting jframe to another jframe
    By ajtambalo in forum Member Introductions
    Replies: 2
    Last Post: May 11th, 2011, 11:24 AM
  2. Pop-out box using a JFrame.
    By ShaunB in forum Java Theory & Questions
    Replies: 6
    Last Post: April 28th, 2011, 12:03 PM
  3. JFrame
    By M3ss1ah in forum AWT / Java Swing
    Replies: 3
    Last Post: February 23rd, 2011, 05:00 PM
  4. JFrame
    By M3ss1ah in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 23rd, 2011, 04:24 PM
  5. JFrame help
    By Uden in forum AWT / Java Swing
    Replies: 0
    Last Post: August 14th, 2009, 01:37 PM