Results 1 to 4 of 4
- 04-04-2009, 08:48 AM #1Member
- Join Date
- Feb 2009
- Rep Power
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
- 04-04-2009, 07:49 PM #2
Relevant source code?
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.
- 04-05-2009, 02:54 PM #4
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...
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:
objectOne = new myObjcet(); // this object implements your interface... ojbectTwo = new mySecondObject(); //this object has getters and setters... ojbectTwo.setMyInterface(objectOne);
- By fred in forum Java AppletsReplies: 7Last Post: 08-17-2010, 06:00 PM
- By cenafu in forum AWT / SwingReplies: 8Last Post: 03-21-2009, 10:34 AM
- By Ramona in forum New To JavaReplies: 18Last Post: 11-22-2008, 06:25 PM
- By bugger in forum New To JavaReplies: 1Last Post: 12-07-2007, 07:20 PM
- By romina in forum AWT / SwingReplies: 1Last Post: 08-07-2007, 05:35 AM