Results 1 to 3 of 3
  1. #1
    Pablo3728 is offline Member
    Join Date
    Aug 2010
    Rep Power

    Default Obtein informaticon from other

    Hello! I have a doubt with the next:

    I have a JFrame called Pablo and other called Pepe;
    Both Jframe have a attribute String text;

    I have a method:

    Java Code:
    public method(JFrame j){
    //I need to do it sssomething with the variable text, like:
        j.text = "hola"
    //But i don't know which JFrame is!!! How Can I do to know what is it?
    Thanks! :)

  2. #2
    minime12358 is offline Member
    Join Date
    Jul 2010
    Rep Power


    Im not quite sure what you are saying. If you want the method to be specific to each frame, you could do this:

    public method(JFrame j, String l)
    j.text = l;
    and call it like this: method(Pablo, "text");

    Alternatively, you may be confusing the use of an argument. When you call a method, you would call it like this : method(Pablo);
    that Pablo is then passed to j. j is now sort of a nickname for pablo. So now you would say j.text = "hola";

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    I would tend to go more towards an OOP solution where the code holding the JTextField in question has a public method called setMyText(String text), and sets the JTextField's text from within this method.

Posting Permissions

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