Results 1 to 4 of 4
  1. #1
    vasavi.singh is offline Member
    Join Date
    Feb 2009
    Rep Power

    Default accessing the text of textfield of one class in another


    I created a frame where I am reading some input data and there only I am displaying it using a dialog box. I would like to open another window on clicking the ok button of dialog box. I would like to access the data of text fields. While accessing the data of first class by using its object it is giving it as zero. the variables declared as static because every object can share the static variables. Still I am getting the value zero.

    Can u people guide me to solve this problem. I have to access all data which were entered in a textfield later I have to store in a file

    Please Respond fast for my query


  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Cambridge, UK
    Rep Power


    Relevant source code?

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


    I would strongly advise against using static variables here as this is not a good reason for using them. You may do well to use an observer pattern design here.

    I will also second the dog's request for relevant source code.

  4. #4
    markw8500's Avatar
    markw8500 is offline Senior Member
    Join Date
    Jul 2008
    Pennsylvania, USA
    Rep Power


    There are a couple of ways to do this... But the best way is to use an interface... I always have a hard time useing Interfaces, so dont get fustrated if it blows up the first time you try it...
    The first thing you want to do is create the interface class... In the call you want to create your method... Say...

    Java Code:
         public void passText(String text);

    Now in your class that is doing something with the dext you want to implement the interface... There is where you will be able to do what ever you want with the text...

    Now in the class that is sending the text you want to create the interface and have getters and setters for the interface...

    Finally in the class where you create objects for both of the classes above, you want to set the interface like so:

    Java Code:
    objectOne = new myObjcet(); // this object implements your interface...
    ojbectTwo = new mySecondObject(); //this object has getters and setters...
    Now if everything goes righ you sould be able to have one object talk to another...

Similar Threads

  1. Replies: 7
    Last Post: 08-17-2010, 07:00 PM
  2. Replies: 8
    Last Post: 03-21-2009, 10:34 AM
  3. Replies: 18
    Last Post: 11-22-2008, 06:25 PM
  4. Randomly accessing a text file
    By bugger in forum New To Java
    Replies: 1
    Last Post: 12-07-2007, 07:20 PM
  5. Replies: 1
    Last Post: 08-07-2007, 06:35 AM

Posting Permissions

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