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

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) {

//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();


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

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

private void handleInputData() {
data.name = "John";
data.address = "Swing Road 1"

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 :-)


About | Sitemap | Contact