|
-
Mar 18th, 2002, 02:08 AM
#1
Thread Starter
New Member
Passing data in a program with GUI, HOW ?
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.
-
Mar 19th, 2002, 02:37 PM
#2
Dazed Member
You could put getters and setters in your classes.
Then retrieve the needed values via those methods.
Code:
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());
}
}
-
Mar 20th, 2002, 11:49 AM
#3
Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|