This document describes how use JDK 1.2.1 to run GridCity. It
assumes that your computer has JDK 1.2.1 (which you can download from
java.sun.com) and Windows 95, 98 or NT. We will cover the following topics: GridCity
The first step is to get GridCity onto your computer. You should certainly store GridCity on your computer in the place that makes the most sense to you, but for purposes of our directions, we will assume that GridCity is in the C:\Temp directory.
There are two ways to get a copy of GridCity into C:\Temp:
We will be using JDK 1.2.1 to access and use files from GridCity. Instructions on how to use JDK and an example
showing how JDK and GridCity work together are in the JDK 1.2.1 section of this page.
Downloading GridCity from the Internet
GridCity and instructions for downloading it are on the internet at https://dataprivacylab.org/activetutors/gridcity/download.html.
Copying GridCity from a Diskette
If you have a copy of the GridCity program on a diskette, insert your diskette into your computer's disk drive and use Windows Explorer to navigate to the A: drive. Find the folder GridCity-1.1 and copy it into the C:\Temp directory.
JDK 1.2.1
Working with Java involves two processes:
·
making and editing programs
·
compiling and running programs
First let's discuss compiling and running existing programs. You will then have the tools you need to make and edit programs.
We will use JDK 1.2.1 (hereafter called JDK) to compile (make our code readable to the computer) and run our Java programs.
Run the Command Prompt program in order to start JDK. To do this, left-click on the Start button at the bottom lefthand corner of your screen. A menu will appear.
Choose Programs from the menu. Another menu will appear. Select Command Prompt, and the Microsoft Windows
Command Prompt (DOS) screen will appear:
We will be entering our commands onto the Command Prompt screen.
To make sure JDK is working, let's run a sample program. For our sample, let's use Demo, which should now be in C:\Temp with the rest of our GridCity files. In the instructions below, the text that the Command Prompt screen outputs to you appears in bold type. The text that you should type onto the screen appears in regular type.
The Command Prompt screen will say:
Microsoft(R) Windows NT(TM) (C) Copyright 1985-1996 Microsoft Corp. C:\users>
Change to the GridCity directory by typing:
C:\users>cd\Temp\GridCity-1.1and hitting the Enter key.
C:\TEMP\GridCity-1.1> c:\jdk1.2.1\bin\javac Demo.java
and hitting Enter.
To compile any program, you will need to type "c:\jdk1.2.1\bin\javac" and then the name of the program. If later you write a program called "Idea.java", you can compile it by typing "c:\jdk1.2.1\bin\javac Idea.java".
C:\TEMP\GridCity-1.1>Otherwise, a description of the kinds of problems found will be reported. You can only move on to the next step and run the program if the program compiles successfully.
C:\TEMP\GridCity-1.1 c:\jdk1.2.1\bin\java Demoand hit Enter.
Here's a shortcut that will work on a Windows NT machine: You can hit the up arrow on your keyboard, the Console Output screen will enter the last thing you typed for you: C:\TEMP\GridCity-1.1 c:\jdk1.2.1\bin\javac Demo.javaYou can then just edit out the "c" at the end of "java" and the ".java" extension on "Demo" before you hit Enter. In fact, you can use both the up and down arrows to cycle through the various things you have entered since you opened Command Prompt. |
When the Demo program runs, the van moves ahead two spaces, turns left three times, and then moves ahead two
more spaces. After the program has run
successfully, GridDisplay will look like this:
If your GridDisplay screen looks like the one above, you have now successfully used JDK to run a GridCity program.
Editing Programs
We will edit programs in a text editor such as Notepad. (We use Notepad for our examples.) Let's edit the program Demo. (The Tutor program will discuss in detail how to write code. The following is an example to illustrate how to use Notepad to edit programs.)
andie.ahead(); andie.ahead();
The end part of our program will now look like this:
Writing Programs
We will also use a text editor (our examples use Notepad) to write our own programs from scratch. (The Tutor program will discuss in detail how to write code. The information provided here is to enable you to use a text editor to write programs.)
Type your program onto a blank screen in Notepad. When you first open Notepad, you automatically have a blank screen to work with. If you have been working and have someting on your screen already, you can get a blank screen by selecting New from the File menu.
Our programs will be starting with the words "public class," and then a name. In our example below, "Example" is the name of our class. This name can actually be anything you want it to be. The important thing to know when you are writing a new program is that, in Java, all programs will have exactly one class, and the name we give to any program we write has to be the same as the name of the class that the program contains. If "Example" is the name of our class, then "Example.java" must be the name of our program. Java is case sensitive, so "Example" and "example" are not the same name.
When you want to save your work, do the following:
It is a good idea to save your work often. If you experience electrical or hardware problems, you could lose any unsaved work.