Results 1 to 3 of 3
  1. #1
    iNko is offline Member
    Join Date
    Dec 2012
    Posts
    55
    Rep Power
    0

    Default How do i pass variable that i entered in jFrame, into jPanel?

    Hey, i used to pass a variable from a textfield from jFrame1 into jFrame2 with this code:
    Java Code:
    String info[] = new String[1];
    info[0] = txtusername.getText();
    jFrame2.main(info)
    then pass this into main method of jFrame2:
    Java Code:
    valuefromjFrame1= args[0];
    and that was it..

    now i want to do the same, except i wanna pass a variable from jFrame1 into jPanel..

    i tried this:
    Java Code:
    String info[] = new String[1];
    info[0] = txtusername.getText();
    jPanel.main(info)
    then created a new public static void main (because there was none in jPanel), and passed it:
    Java Code:
    public static void main(String args[]) { 
    valuefromjFrame1 = args[0];   
    }
    got no errors, but the value is empty..

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: How do i pass variable that i entered in jFrame, into jPanel?

    As an aside - any reason you are using the main method so many times? It is meant for application entry, and I'd recommend writing more meaningful setter methods. That being said, from what you posted, we can only guess what is going on. I'd recommend an SSCCE

  3. #3
    iNko is offline Member
    Join Date
    Dec 2012
    Posts
    55
    Rep Power
    0

    Default Re: How do i pass variable that i entered in jFrame, into jPanel?

    Quote Originally Posted by doWhile View Post
    As an aside - any reason you are using the main method so many times? It is meant for application entry, and I'd recommend writing more meaningful setter methods. That being said, from what you posted, we can only guess what is going on. I'd recommend an SSCCE
    Im very new to java and most of the time i dont even know what the code im writing actually means.. I found a very detailed 'pass variable from jframe to jframe' tutorial, copied it, and it worked for me.

    Anyways, i think i got my problem solved, i had a typo in my code.. Used the same way i passed variable from frame to frame.

Similar Threads

  1. Replies: 2
    Last Post: 07-28-2011, 09:01 AM
  2. Replies: 5
    Last Post: 06-14-2010, 06:10 PM
  3. Replies: 2
    Last Post: 04-18-2010, 04:48 AM
  4. Jframe pass variable to Applet
    By wayn in forum AWT / Swing
    Replies: 0
    Last Post: 03-10-2010, 09:54 AM
  5. How pass variable from jsp to servelet
    By shiva in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 04-22-2009, 01:55 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
  •