a gui game engine that saves your files?

I asked this in another post, but I don’t think I expressed it very well… so now that I have time I’ll try again.

I’m using borland to create a gui that will be something like RPGMaker2000. Via widgets I will manipulate how the game looks, where sprites go, what tilesets go in which rooms, etc. When I’m done creating my game, I want to save it as a game class that extends applet, implements runnable, etc. I was thinking, the “save” button could save a text file that writes out all the stuff that’s not varialble, like:
out.println(“import java.awt.; import java.applet.;… public class videoGame extends…”)
then I’d concatonate variables in that I changed in the gui. When all is done, it would be saved as a text that I could just change the extension to .java and compile and go.

Anyway, the idea is stupid, but hopefully that will give you a better idea of what exactly I’m trying to do. Basically I’m trying to either save a complete java project (not just text or object data binaries) that ISN’T the java project I’m presently in (which is the gui), or manipulate a template that would have all the stuff i need for this game and I could just change the variables. I’m dumb, and all I know about regarding template manipulation is random access, which wouldn’t work because it requires that the input be the exact same length in terms of letters as the template.

Any ideas?

I’m sorry, I’m still confused as to what you’re trying to do?

The generated source code would be the RPG game logic? If you just want to save some source code to a file just using a java.io.FileWriter?

It would probably be nicer if your gui saved it as a .java and compiled it for the user (this isn’t tricky, its all given to you in tools.jar of the JDK install).

Sorry not to be more help,

Kev

That would be great if I could do that!
for the life of me i can’t find info on the subject dumbed down enough for me to understand (the tools.jar that is, i couldn’t figure out how to use it to save files, only to archive them).
Basically my gui will be a .java that creates a different .java (and hopefully, like you said, compiles and runs it too). I’ll use the gui to modify variables, then once the user hits “save” those variables will be inserted into a template, and that now modified template is saved as its own .java, without saving any of the gui information (except of course the modified info used in the template).
if that is indeed what tools.jar does, know of any sites or documentation on the subject?
Thanks once again kev, you are being most helpful!

Ok, file writing… assuming you have your text in a JTextField called code.


String text = code.getText();

PrintStream out = new PrintStream(new FileOutputStream("code.java"));
out.print(text);
out.close();

Dumps it out to a file. Next you want to compile it, here:

http://mindprod.com/jgloss/javacexe.html

Half way down the page it starts talking about “Programmatic Invocation”. The bit in particular you want is:


sun.tools.javac.Main comp = new sun.tools.javac.Main( System.out, null );
boolean success = comp.compile( new String [] { "HelloWorld.java"} );

You’d need tools.jar in your classpath for that to work. However, this whole thing sounds a bit ropey, you might want to consider what exactly you want to achieve and consider whether you really need to progmatically generate code?

EDIT: This might help too, http://www.javaworld.com/javatips/jw-javatip131.html

Kev

Kev, may the hair on your feet never fall out. That answered my question exactly.

it still sounds ropey, eh? Well, let me try one more time to explain exactly what I’m trying to do. Don’t feel obligated to find out how to do it, you answered the question exactly with that last link, and thank you very much.
Anyway, as an example if I wanted to create an applet with hundreds of components (myriads of different buttons, images, sliders, etc) then it would be MUCH easier and time saving to do that through a gui like borland Jbuilder, instead of programatically. Similarly, I want to make a game that reuses certain classes (sprites, background, tiles, etc). If i wanted to make a full game, it would take FOREVER to do the whole thing programatically, and it would be a tedius copy/paste/modify exercise. So I want to make a “borland Jbuilder” so to speak, a gui that makes a separate program. When you save your java file in jbuilder, it doesn’t save it as part of jbuilder, but a completely separate .java. Similarly, I want to use my gui.java to save a project that I could later modify called game.java.
An example is RPGMaker 2000 (http://www.gfxartist.com/features/articles/279). in rm2k you select a sprite and drop it onto a canvas, then you select a portion of the canvas to fill with a certain tile, etc. you specify where you’re main character will start, what certain events are invoked by certain actions, etc… finally, you save your project and run it. It’s more work to begin with to actually MAKE rpgmaker 2000 than it would be to simply program a small game, but when the games start getting bigger it saves time this way. Does that make more sense?

Sure does, its exactly what I thought you were getting at. These systems (RM2k for instance), rarely generate code since (or at least not code that anyone bothers to understand). Generally they go for a set of core object built into an engine with a dialect of one type or another that manipulates the engine.

The reason its generally done without code is so that the internals can be changed which still keeping a backwards compatibility. While this is possible using Java (since its such a wonderful language), I still maitain that you have to have a pretty strong case to justify using something like BSH, or code generation.

Kev