Click to See Complete Forum and Search --> : Passing data in a program with GUI, HOW ?
goguest
Mar 18th, 2002, 02:08 AM
I've written a java application consisting of three classes, two of which are coded to construct two different user interfaces for acquiring data from the user while the remaining one consists of the main() function and controls the flow of the entire program.However, due to the property of event-driven programming, I find it very hard to pass data from the two GUI back to the main class for further processing. And my question is, what is the best and efficient way of passing data between classes in a GUI program such as my one, and how ? Appreciate if a simple example could be given ! Thanx.
:rolleyes:
Dillinger4
Mar 19th, 2002, 02:37 PM
You could put getters and setters in your classes.
Then retrieve the needed values via those methods.
class GUI{
private String fname;
private String lname;
public void setfName(String fname){this.fname = fname;}
public String getfName(){return fname;}
public void setlName(String lname){this.lname = lname;}
public String getlName(){return lname;}
}
public class X{
public static void main(String[] args){
GUI gui = new GUI();
gui.setfName("Bill");
gui.setlName("Kasmeyer");
System.out.println(gui.getfName());
System.out.println(gui.getlName());
}
}
daveyboy
Mar 20th, 2002, 11:49 AM
Another example is to use Observers and Observables, it's a powerful method of interprocess communication, if you have the GUIs as observables, and the main class as an observer for both GUI classes it will allow it to monitor changes, or actions that you specify. It also is probably a good way because of how the jvm handles the observable and observer processes.
:) :( :o :p ;) :D :cool: :rolleyes: :mad: :confused: :eek:
Infinity isn't large it's just incomprehensible..........
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.