A Peek into a Mind

Civax Personal Homepage

JavaSDL issues

I’m writing the fremework for Beit Berl College GEMOLOGY program. I think it will be using javaSDL. Therefore, I collect a few links here for my personal use.

Installing javaSDL on Eclipse:

  1. Download sdljava-0.9.1-win32-bin.zip and optionally sdljava-0.9.1-src.zip (It contains the source code for the samples, very handy).
  2. Extract to any directory (e.g. C:\Java\sdljava-0.9.1).
  3. Click Start -> Settings -> Control Panel -> System -> Advanced -> Environment Variables and append C:\Java\sdljava-0.9.1\lib to the Path system variable.
  4. Go to C:\Java\sdljava-0.9.1\bin and execute testsprite.bat - If it works, congratulations, 75% done.
  5. Open Eclipse, create a new project, add a source file to it and paste the following into it:

    import sdljava.*;
    import sdljava.video.*;

    class HelloSDL {
    public static void main(String[] args) {
    final String caption = "Hello, SDL!";
    System.out.println(caption);
    try {
    SDLMain.init(SDLMain.SDL_INIT_VIDEO);
    SDLVideo.wmSetCaption(caption, caption);
    SDLSurface screen = SDLVideo.setVideoMode(640, 480, 24, 0);
    java.lang.Thread.sleep(2500);} catch(Exception e) {
    e.printStackTrace();
    } finally {
    SDLMain.quit();
    }
    }
    }
  6. Right click the source file and choose Run As … Run.
  7. If there isn’t already an entry below “Java Application”, create one. Ensure that the main class is set to “HelloSDL”.
  8. Switch to the Arguments tab and add the following to VM arguments: -Djava.library.path=C:\Java\sdljava-0.9.1\lib
  9. Open the project properties, select Java Build Path -> Libraries and click on Add external JARs, then choose C:\Java\sdljava-0.9.1\lib\sdljava.jar and click Open.
  10. Run the project. If it works, that’s all there is to it!