Merging two programs into one

J

JNU

I am a Java newbie. I have written two separate programs - one
provides a gui with buttons and a textbox and the other does some
communication with hardware.

What I would like to do is to merge them somehow so that when a button
is clicked on the gui the communication part runs.

How can this be done?
 
S

support

You don't need to merge them.

Providing your communication Class has methods that are accessible to the
GUI class (they are either public or package visibility and the comms class
is in the same package as your gui class), then you can instantiate your
comms class from the GUI class and invoke the methods that you need to
perform the comms.

If this doesn't make any sense then pick up a book on Object Oriented
development and read up on OO concepts, and then this should all fall into
place.

In order to trigger invoking the methods on the comms class from your GUI
class you will need to implement some event handling. If you haven't got
this far, then check out the Java tutorial on the Sun site:

http://java.sun.com/docs/books/tutorial/uiswing/overview/event.html
 
A

Andy Fish

At the end of the day, any java application just comes down to a pile of
class files.

As long as the class files are all on the classpath, you can invoke any
class from any other.

what makes them two distinct 'programs' in your mind is probably that you
have two separate 'main' methods. As long as you factor all the logic out
from the comms part so that it isn't in the main method, you can call it
from the GUI part. You can leave the main method in which will allow you to
invoke it as a stand-alone if necessary.

as a previous reply said though, you need to have some understanding of OO
and component software to make sense of it all.

Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top