Results 1 to 5 of 5
  1. #1
    Renegade85 is offline Member
    Join Date
    Nov 2007
    Posts
    25
    Rep Power
    0

    Default [SOLVED] Need help using variables between classes

    Ok, so i'm doing a GUI for a program i'm making. It has 4 classes (MainPanel, Panel1, panel2, Panel3) and i have referenced panel2 in panel 3 in it's constructor i.e.

    Java Code:
    public Panel3(Panel2 panel2)
    The objects are all created in the main class of the program i.e. MainPanel
    I want to get the information put into Panel2 and use it in a method of Panel3. I can't seem to figure it out though :confused:

    The info i want to take is from JLabels

    Any help appreciated, thanks ;)
    Last edited by Renegade85; 04-21-2008 at 04:10 PM.

  2. #2
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    8

    Default

    Hmm.. I would start with constructing the Panel2 before you construct Panel3... in addition, make the data you want to retrieve from Panel2 static.... what have you got so far for code?
    Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
    Want to voice your opinion on your IDE/Editor of choice? Vote now!
    Got a little Capt'n in you? (drink responsibly)

  3. #3
    Renegade85 is offline Member
    Join Date
    Nov 2007
    Posts
    25
    Rep Power
    0

    Default

    Quote Originally Posted by CaptainMorgan View Post
    Hmm.. I would start with constructing the Panel2 before you construct Panel3... in addition, make the data you want to retrieve from Panel2 static....
    Already constructing Panel2 first ;) Will try making variables in Panel2 static :)

  4. #4
    Join Date
    Apr 2008
    Location
    Fort Wayne, Indiana
    Posts
    62
    Rep Power
    0

    Default

    Let me know if i'm getting this right.

    Step 1: Create main panel
    Step 2: Add Panel 1
    Step 3: Add Panel 2
    Step 4: Add stuff to panel 2
    Step 5: Add Panel 3 by passing Panel 2

    Code snippets may help.

  5. #5
    Renegade85 is offline Member
    Join Date
    Nov 2007
    Posts
    25
    Rep Power
    0

    Default

    Have it fixed now so its ok :)
    Last edited by Renegade85; 04-23-2008 at 09:54 AM.

Similar Threads

  1. boolean variables
    By ravian in forum New To Java
    Replies: 3
    Last Post: 12-31-2007, 04:58 AM
  2. Initialize variables before use
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-22-2007, 11:22 AM
  3. Variables
    By mew in forum New To Java
    Replies: 3
    Last Post: 12-11-2007, 12:44 PM
  4. JSP - session variables
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-02-2007, 09:22 PM
  5. Saving Variables
    By Fish in forum New To Java
    Replies: 6
    Last Post: 06-25-2007, 08:20 PM

Posting Permissions

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