View  Info  Edit

Home > Getting Started > Java & Eclipse

Java

Java is a programming language developed by sun (see http://java.sun.com). Java is cross-platform meaning that, in theory - your Java program can run on all major operating systems with no modifications to the source code. Java programs can also run as applets inside a web page, and (with certain limitations) on mobile devices, such as phones and PDA's.

Getting Started

To start writing Java programs, you will need the Java SDK. This comes in a few different versions, but chances are you'll want the 'Java 2 Software Development Kit, Standard Edition' - more commonly known as the JDK, which you can download from the Java SE homepage. All you really then need to start developing Java programs is a text editor, and the Java Compiler to convert your java program into something runnable by the computer you're using. In reality however, it is much easier to use an Integrated Development Environment (IDE) because it simplifies the process of creating a runnable program into buttons and menus. A popular Java IDE used by the society (and many other people!) is Eclipse.

Eclipse

Eclipse is a free Integrated Development Environment (IDE) for writing code. It supports many languages, but is mainly used by the society for Java development, as Microsoft offer other, (also free!) IDE's for C-based languages.

Download

Eclipse can be downloaded from the eclipse.org website. There are several different versions, you will most likely want the 'Eclipse IDE for Java Developers'. Download the program for your platform and un-zip it where you want it. Eclipse does not require any installation, just download it and unzip it to wherever you want.

Using Eclipse

Eclipse will need to create a workspace where it will store all your code as well as additional project files. This defaults to inside your 'My Documents' / Home folder, but you can use whatever folder you like. Although it is possible to use Eclipse simply as a text editor, it also offers many more functions, such as code completion, syntax highlighting and debugging. To get the most of these, you need to create an eclipse project. This will create a folder inside your workspace where your project will be contained.

The Minigames Framework

If you are new to java, programming in general - or just want to make a quick game, you can try using the 'Minigames' framework - a simple library written by the society which packages several quick mingames into a single program. The library also offers a codebase to make writing a game much easier.

Setting up the Minigames Framework

Note: These instructions are written based on Eclipse v3.1. If you are using a different version there may be slight differences, but the general process will be the same. To create a new project that uses the minigames framework, simply follow these steps:

  • Download the framework! - See the Minigames page for download instructions.
  • Unzip the framework to any directory.
  • Startup Eclipse. It will ask you to choose a folder to use as the eclipse workspace. Go with the default folder, or pick your own - this is where all your projects will be stored on your computer.
  • Create a new Java Project. (Click File → New → Project and select 'Java Project'.)
  • Give your project a name using the textbox at the top of the screen, and check the 'Create project from existing source' option. Click the 'Browse' button and select the folder where you extracted the framework - then, click Next. You may leave other options as they are.
  • Now, we need to add the framework to your project as a Library. To do this, select the Libraries tab, click Add JARs.... Pick the minigames.jar file. You'll find it in the folder with the project name you entered on the previous page.
  • Click Finish and the dialog box will close.

You should now be able to see your project in the Package Explorer on the left side of the screen - click Windows→Show View→Package Explorer if you cannot see it. If you expand the project node, you can see the files inside the project. The java code for the minigames will be inside the (default package) folder. The JRE System Library (or similar) folder contains internal Java classes, and the minigames.jar folder contains the minigames library - you don't have to worry about the contents of these two folders. The additional files you see at the end are .ini files that describe each minigame, a 'games.list' file which lists the minigames available to the application and various images/sound files used in the sample minigames.

Running the Project

To run the program, you will need to setup a configuration, so eclipse knows how to compile your program and which part of the code to run first. This may seem complicated, but if you're new to Java it's much easier than running the compiler manually...

To set up the project, do the following:

  • From the Run menu, click 'Run...'.
  • This brings up another dialog box. You need to setup a new 'Java Application' configuration. You can do this by selecting Java Application from the list and clicking the New button.
  • Give the configuration a name (it is usually easiest to give it the same name as the project. You don't have to worry about project/configuration names conflicting with each other.)
  • You now need to tell the configuration which Project and which Class to run. In the Projects section, click Browse and select your project.
  • In the 'Main class' section, check the 'Include libraries when searching for main class' option, and click the Search... button.
  • From the dialog that appears, select Main from the Matching Types list, and then minigames from the Qualifier list. This configures the eclipse to launch the minigame framework when you run your application. This is important as the code inside your minigame relies upon the code inside the framework library.
  • The configuration is now complete. Click Apply to save your changes, and then click Run to run the framework with the sample games.

Your program will now compile and run. If this happens then everything is set up correctly and you're ready to go! If you have any difficulties then don't be afraid to ask for help - either in person, on the forums or by emailing the exec. We'll be happy to help, honest...

What Now?..

Now everything is setup and working, you should check the Minigames Framework page for instructions on setting up your own game. You may find it useful to check the code for the 3 sample games before getting started - remember, you can find these inside the 'Default Package' folder.