Results 1 to 5 of 5
  1. #1
    pager is offline Member
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Default [ASK] get text value from other JFrame

    hi all, is it possible to get the value from other JFrame eg: txtName.getText();

    and display it to the other JFrame eg: txtName.setText();

    thx

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    Yes it is!

  3. #3
    RichersooN is offline Senior Member
    Join Date
    Jan 2011
    Location
    Rizal Province, Philippiines
    Posts
    167
    Rep Power
    0

    Default

    More formal soft. eng. technique... use getters and setters

  4. #4
    pager is offline Member
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Default

    can you give me some reference i cannot find it nowhere..thx

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    Same way you pass info between any 2 objects: create instance and call method.

    Java Code:
    class ObjA {
        private String data = "hello";
    
        public String getData() {
            return data;
        }
    }
    
    class ObjB {
        private String moreData;
    
        public void setMoreData(String s) {
            moreData = s;
        }
    
        public String getMoreData() {
            return moreData;
        }
    
        public static void main(String[] args) {
            ObjA aaa = new ObjA();
            ObjB bbb = new ObjB();
            bbb.setMoreData(aaa.getData());
            System.out.println(bbb.getMoreData());
        }
    }
    Or
    Java Code:
    class ObjA {
        private String data = "hello";
    
        public String getData() {
            return data;
        }
    }
    
    class ObjB {
        private ObjA aaa = new ObjA();
        private String moreData;
    
        public void setMoreData() {
            moreData = aaa.getData();
        }
    
        public String getMoreData() {
            return moreData;
        }
    
        public static void main(String[] args) {
            ObjB bbb = new ObjB();
            bbb.setMoreData();
            System.out.println(bbb.getMoreData());
        }
    }
    Or
    Java Code:
    class ObjA {
        private String data = "hello";
    
        public String getData() {
            return data;
        }
    }
    
    class ObjB {
        private ObjA aaa;
        private String moreData;
    
        ObjB(ObjA other) {
            aaa = other;
        }
    
        public void setMoreData() {
            moreData = aaa.getData();
        }
        public String getMoreData() {
            return moreData;
        }
    
        public static void main(String[] args) {
            ObjA aaa = new ObjA();
            ObjB bbb = new ObjB(aaa);
            bbb.setMoreData();
            System.out.println(bbb.getMoreData());
        }
    }

Similar Threads

  1. Replies: 13
    Last Post: 09-29-2010, 10:55 PM
  2. Replies: 1
    Last Post: 04-26-2010, 01:02 PM
  3. how to point cursor on the 1st text field in a jframe
    By VineetKumar in forum AWT / Swing
    Replies: 4
    Last Post: 04-17-2009, 02:58 PM
  4. launching Jframe from text field
    By crunchymonkey in forum AWT / Swing
    Replies: 4
    Last Post: 10-15-2008, 02:50 AM
  5. How to display scrolling text and image on a JFrame
    By Abhi_vk in forum AWT / Swing
    Replies: 1
    Last Post: 06-20-2008, 10:19 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
  •