How can you get information from a running applet?
I'm running a little开发者_如何学C applet game in the appletviewer, and I have another java program that periodically tries to get the 'score' field from the applet.
However right now the way I'm trying to do this is (slightly pseudocode-ified):
Applet myGame = Game();
Runtime.exec("appletviewer Game");
score = myGame.getCurrentScore;
The problem is that the applet variable that I initialize doesn't correspond to the Applet created by the appletviewer. How can I resolve this?
You wouldn't be able to do that. A few options:
- Write your information out to a file periodically to be read in by your secondary process.
- Write your information to a database to be read by your secondary process.
- Rearchitect your game to be called entirely from your secondary process so it has access to its memory. (So instead of using exec, be like
myGame.startGame()
.)
精彩评论