You are on page 1of 14

Getting Started With JCreator The first thing to do with JCreator is to create a workspace.

A workspace is an area where you can store a project or a set of related projects. For me, the best way to create a work space, is to create a folder with the same name as the workspace. I do this before JCreator is opened. So create a folder, workspace, on your flash drive with the name First Programs, or some other name that you prefer.

Now a project is a group of related classes. Several projects can go in one workspace. Also, a project can consist of only one class. Our first example will be a project that consist of only one class. So let's get started. So you've already carried out the first step. That is, before you started JCreator, you made a folder for a workspace called First Programs. The next step is to start JCreator. Part of the window that will display is shown below.

Even though we created a folder for the workspace, we still have to let JCreator do the same. So click File, New, and then Blank Workspace.

Then type in the words First Programs in the name field. Then click the three ellipses and browse to the workspace folder, and then Finish.

When the following box displays, click Yes.

You will then be taken back to the initial screen without the JCreator information, part of which is shown next.

The next thing really isn't a step. We just want to take a peek at the two files that JCreator makes when a new workspace is created. To see these files, minimize JCreator and open the workspace folder.

Now that we have a workspace, we can put projects in it. We will look at three examples. In example 1, we will create a project that only has one class, and we will code this class from scratch. In example 2, we will import some existing classes into a project; and, in example 3, we will see how JCreator can be used to run the GridWorld case study. In this last example, we will see how to make a jar file part of a JCreator project. Example 1, Create a project with only 1 class that we code from scratch Select File, New, and then Project.

When the next window comes up, select Empty Project and then Next.

When the next window comes up, put example 1 in the name field and then click Finish. Wait while the project builds. Then you will have to click Finish again.

When the next window comes up, make sure that box next to the JDK version... is checked and then click Next.

When the next window displays, part of which is shown next, you will see the name of the project in the top left hand corner.

To add a class to this project, right on the name and then click Add and then New File.

Then choose Empty Java File and then Next.

When the window displays, type in the name of the class in the Name: field and click Finish.

An editor opens, part of which is shown.

Input the following program under the Hello.java tab. class Hello { public static void main(String args[]) { System.out.println("Hello and welcome to JCreator"); } } See the diagram below for compiling and executing the program. The tabs can be found to the right center of the menu bar.

Example 2, Create a project and import the classes, for example, that were done in TextPad First, create an example 2 project in the same workspace. All the steps are the same, except for the name of the project. In this case, the name is project 2. Suppose that the files for this project were created using TextPad and reside in a folder on the desktop called fraction. Note that in the File View window the example 2 project has been added. It is listed under example 1.

We want to import the files from the fraction folder on the desktop to this project. So, from JCreator, right click on the example 2 folder and then select Add and then Add Existing Files.

A window will pop up that will allow you to browse to the files you want to import.

Select the two files and then click Open. Another window will pop up. Click Add. Note that since there are two files, you will have to click Add twice. If there were 10 files, you would click Add ten times.

Then click on the + sign next to the example 2 project name. Double click on the two class files. They should open in the editor.

Finally, compile and run the project as with example 1. Example 3, Create a project that will run the GridWorld case study. We will see how a box bug runs in the grid. First note that when you unzip the GridWorld download, there is a folder in it called GridWorldCode. There is a subfolder inside this called projects, and inside the projects folder there is a folder called boxbug. The boxbug folder has two files, BoxBug.java and BoxBugRunner.java. You will want to, using the same workspace, create a project called example 3. Do this the way that you created the projects in the other two examples. Then you will want to import the the BoxBug.java and BoxBugRunner.java files into this project, just like you did with the files in example 2. Next, note that the GridWorldCode comes with many files. It is not practical to open all of these files every time you run GridWorld. So most of them have been put in a jar file that the GridWorld driver can access. This jar file must be made part of the project. To add a jar file, select Project and then Project Settings....

Then select Required Libraries and then New.

Then type a name for the jar file in the Name field, such as GridWordJar. Then select Add and then Add Archive....

Then go to the GridWorldCode folder and open the archive file.

Then click OK.

When the next screen comes up make sure the you put a check in the box and then click OK.

Finally, compile and run the project.

You might also like