Passing data in a program with GUI, HOW ?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   go_guest
Posted On:   Sunday, March 17, 2002 10:56 PM

			
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.

Re: Passing data in a program with GUI, HOW ?

Posted By:   Anonymous  
Posted On:   Monday, March 25, 2002 02:35 PM


Use callback method parameters, something like




class Main {

private GUIClass gc1;

public void receive(Object data) {
database.setName(data.name);
database.setAddress(data.address);
}//receive

//constructor for Main class
Main() {
//passing this instance as reference to gui class
GUIClass gc1 = new GUIClass(this);
}

public static void main(String args[]) {
Main m = new Main();

}//main
}//Main

class GUIClass {
private Main m;
private MyDataObject data = new MyDataObject;

//Constructor with reference to main class
GUIClass(Main m) {
this.m = m;
}//constructor

private void handleInputData() {
data.name = "John";
data.address = "Swing Road 1"
m.receive(data);
}//handleInputData
}//GUIClass




This is the most simple way to do it, I think. Maybe too simple for a real-world-app, but it's a start ...
(eh, and don't expect this to compile without some cleanup :-)


--
jonmartin.solaas@mail.link.no

About | Sitemap | Contact