views:

21

answers:

1

I have a Java game i'm creating and each window is a seperate JFrame with its own components.

How would I get about calling variables from other .java programs? Not quite sure how to do that.

+1  A: 

A running JVM instance has no access to objects living in a different instance. Communication between java virtual machines has to be done with other means.

A practical way is to establish a TCP/IP based interface. One application acts as a server (opens a port) and listens to requests for data. TCP/IP based client/server solutions are not too complicated in Java.

Another rather simple alternative is using a shared file on the file system. The data provider updates this file on changes, the 'client' monitors this file and loads the content, whenever it detects update/change (monitor modification timestamp).

And to mention a third approach: Java Management Extensions (JMX) would help too. JConsole (part of the jdk) is a practical example on how to connect to a separate JVM and get access to ('public') data and methods.

Andreas_D
The file-based solution, though wonderfully simple, sounds like it may run into trouble with processes overwriting each others' updates. The JMX idea, though, is very cool and elegant.
Carl Smotricz
@Carl - JMX is my favorite too, but quite challenging ... beginners should start with files to have an early taste of success :)
Andreas_D