| | |
How to? Java GUI interacting with another Java class
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2009
Posts: 2
Reputation:
Solved Threads: 0
Hi guys,
I'm writing a Java programme, one with GUI for a project in college.
We separated the work into a few guys doing a few standalone Java classes. These standalone Java classes are run by doing the usual:
java -jar XXX.jar through the console. The functions of the class are issued through by typing commands into the class by way of the console. e.g. /chat mynick message
A few of the other guys designed the GUI.
The question now is.. how do we integrate these two together? I've been googling but I dont know a good sign post.
I'm thinking we need to write an interface between the GUI and the Java classes. Is there a term for this?
We're lost, please advise!
I'm writing a Java programme, one with GUI for a project in college.
We separated the work into a few guys doing a few standalone Java classes. These standalone Java classes are run by doing the usual:
java -jar XXX.jar through the console. The functions of the class are issued through by typing commands into the class by way of the console. e.g. /chat mynick message
A few of the other guys designed the GUI.
The question now is.. how do we integrate these two together? I've been googling but I dont know a good sign post.
I'm thinking we need to write an interface between the GUI and the Java classes. Is there a term for this?
We're lost, please advise!
Java GUI is just another class. You can create instances of other classes inside and call their methods.
Small, silly example:
And in another class (or in main)
Small, silly example:
Java Syntax (Toggle Plain Text)
class Person { public String name; public int age; public Person() { } }
Java Syntax (Toggle Plain Text)
class Print { private Person person; public Print(Person p) { person = p; } public void print() { System.out.println(person.name+";"+person.age); } }
And in another class (or in main)
Java Syntax (Toggle Plain Text)
Person pers = new Person(); pers.name = "Name"; pers.age = 10; Print pr = new Print(pers); pr.print();
Check out my New Bike at my Public Profile at the "About Me" tab
•
•
Join Date: Apr 2008
Posts: 972
Reputation:
Solved Threads: 145
Add methods to the stand-alone classes so their functionality can be called from Java, eg public sendChat(String nick, String message).
Then, in the GUI have entry fields for the required data, when the user clicks OK, get the data from the fields and use it to call the functionality via these new methods.
ps It's called MVC. Model (ie the functionality) View (ie the user interface) and Controller (the logic that links the two). In this case, like many others, the controller logic is trivial so it gets combined with the view code.
Then, in the GUI have entry fields for the required data, when the user clicks OK, get the data from the fields and use it to call the functionality via these new methods.
ps It's called MVC. Model (ie the functionality) View (ie the user interface) and Controller (the logic that links the two). In this case, like many others, the controller logic is trivial so it gets combined with the view code.
![]() |
Other Threads in the Java Forum
- Previous Thread: file handling, outof memory error :(
- Next Thread: question about '='
| Thread Tools | Search this Thread |
3d @param affinetransform android api applet application arc arguments array arrays automation binary bluetooth byte capture chat class classes click client code color compare component count database design detection eclipse eclipsedevelopment encryption error event exception fractal game givemetehcodez graphics gridlayout gui guitesting helpwithhomework html ide if_statement image input integer j2me java java.xls javaprojects jni jpanel julia keytool keyword linux list loop macintosh map method methods mobile netbeans newbie object os pong print problem producer program programming project projectideas read recursion replaysolutions rim scanner screen server set size sms sort sql string swing terminal threads time transforms tree ui web windows






