How to? Java GUI interacting with another Java class

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2009
Posts: 2
Reputation: heysebas is an unknown quantity at this point 
Solved Threads: 0
heysebas heysebas is offline Offline
Newbie Poster

How to? Java GUI interacting with another Java class

 
0
  #1
Mar 27th, 2009
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!
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,677
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 226
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: How to? Java GUI interacting with another Java class

 
0
  #2
Mar 27th, 2009
Java GUI is just another class. You can create instances of other classes inside and call their methods.
Small, silly example:

  1. class Person {
  2. public String name;
  3. public int age;
  4.  
  5. public Person() {
  6. }
  7. }
  1. class Print {
  2. private Person person;
  3.  
  4. public Print(Person p) {
  5. person = p;
  6. }
  7.  
  8. public void print() {
  9. System.out.println(person.name+";"+person.age);
  10. }
  11. }

And in another class (or in main)
  1. Person pers = new Person();
  2. pers.name = "Name";
  3. pers.age = 10;
  4.  
  5. Print pr = new Print(pers);
  6. pr.print();
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 972
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 145
JamesCherrill JamesCherrill is offline Offline
Posting Shark

Re: How to? Java GUI interacting with another Java class

 
0
  #3
Mar 27th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC