Running the World of Drawing, Key Events, and Timer using Java 1.4 in Eclipse or other full scale IDE The programs that used the draw.* teachpack in ProfessorJ can be easily adapted for use with Java 1.4 and any Java IDE, such as Eclipse, or the command line program invocation. There are only three minor changes you need to do in programs that use the World: -------------------------------------------------------------------------- Building a project that uses the draw.jar teachpack: - Download the file 'draw.jar' into the eclipse/plugins/ directory - Start a new Java Project, just as you did in the lab, and import your earlier Maze.java file, or any other file that imported 'draw.*' in ProfessorJ - In the Package Explorer pane highlight the 'default package' for your Project - In the Project menu select Properties - In the left pane of the Properties for 'your project' select Java Build Path - On the right hand side of the main panel select Add Variable - In the window that pops up (New Variable Classpath Entry) highlight 'draw.jar' and hit 'OK', them hit 'OK' in the main Properties pane. You can now work on your file that defines the new World. -------------------------------------------------------------------------- The first change in this file is is in the invocation of the method bigBang(...) that starts the timer and the world. there are two variants of this method, the original one that takes one argument, the speed at which the timer ticks should happen. A new variant allows the user to choose whether the World should run the timer, monitor the key events, and monitor the mouse events (such as mouse clicks, mouse moves, etc.) The description of the new variant is: Purpose: Start the world timer and event monitoring as defined by the arguments Arguments: int speed ----- if set to 0.0, do not monitor the timer events otherwise use the given speed in miliseconds as the time interval assumes the value given is non-negative boolean key --- if true, monitor the key events boolean mouse - if true, monitor the mouse events The three programs DrawingWorld, KeyEventWorld, and TimerWorld illustrate the use of this variant. -------------------------------------------------------------------------- The second change is in how the program execution is initiated. All Java Applications start by executing the static method 'main' with the typical header: public static void main(String[] argv){...} This method takes the place of our Examples class. We can include it in our TimerWorld or DrawingWorld, or KeyEventWorld class, or in our Blob class. The method can contain sample data definitions (these act as local definitions in Scheme) and it will include tests of our methods. It will also include the code that will start the World, with the desired event monitoring. To start the World, we need to make an instance of the World and then invoke the methods 'start' and 'bigBang' in a manner similar to what we did in ProfessorJ: instantiate the TimerWorld: TimerWorld w = new TimerWorld(new Blob(new Posn(100, 200), 20)); followed by // start the world, start the timer and key event monitoring boolean testWorld = w.start(200,400) && w.theWorld.bigBang(0.3, w, true, false); or instantiate the KeyEventWorld: // construct an instance of a KeyEventWorld KeyEventWorld w = new KeyEventWorld(new Blob(new Posn(100, 200), 20)); followed by // start the world, start the key event monitoring only boolean testWorld = w.start(200,400) && w.theWorld.bigBang(0.0, w, true, false); or instantiate just the DrawingWorld: // make an example of a drawing world World dw = new World(); followed by // show the world as a canvas of the size 200, 400 boolean testWorld = dw.start(200, 400); -------------------------------------------------------------------------- The rest of the program that uses the draw.ss teachpack should work without change.