Eclipse is installed on the lab machines but it has not been added to the gnome application menu. In order to add it:
The first time that you launch Eclipse you will be presented with the Workspace Launcher dialog. A workspace in eclipse is a directory where all programming projects are stored. To create a workspace for this course:
After Eclipse finishes launching you will be presented with the welcome screen. This screen contains links to information about Eclipse including tutorials to help you learn Eclipse. If you ever want to come back to this screen you can select Help>Welcome from the application menu bar. For now, click on the button with a curved arrow on the far right of the screen to go to the workbench.
The workbench should be empty because there are no projects in the newly created workspace. A project in eclipse is a collection code with a common purpose. For this class, you will create a new project for each lab (and optionally for each assignment). To create a project for today's lab:
Notice that in the Package Explorer panel on the left side of the Eclipse window there is now a folder that represents the project directory. If you click the disclosure triangle next to the new project it will show an icon for the JRE System Library. This is how Eclipse shows that your code is linked to the standard java library (java.util, java.lang, etc). In order to create a program in the project you need to add a java file. To do this:
Notice in the Package Explorer panel that under the lab1 project is the file HelloWorld.java. In the Editor panel there is a tab that contains the contents of the HelloWorld.java file, including the class declaration and the main method declaration. Add a print statement to the main method to print Hello World and save the file (File>Save or ctl-s). Run the program by choosing Run>Run from the application menu bar or pressing ctl-shift-F11. Note that there is no compile step, Eclipse compiles code in the background while you are editing it. The Console panel should appear at the bottom of the application window with the output that would normally appear on the command line.
The file BouncingBall.java animates a ball in a window like we created in class. Download the BouncingBall program to your lab1 project directory. Note that eclipse is slightly picky about how code is added to a project. If you save a file to a project directory, it does not automatically appear in the Package Explorer. To fix this you can choose the project directory in the Package Explorer and then choose File>Refresh from the application menu bar (or press F5). You should now see the added java file in the Package Explorer and double clicking the file will open it in the Editor panel. If you use File>Open to open a file added to the project directory Eclipse will open the file in the Editor panel, but it will not let you run the program because it has not been added to the project.
Run the BouncingBall program. When the ball gets to the edge of the screen, it just keeps going. Modify the program so that when the ball hits the edge of the screen it should change direction as if it bounced off of the edge. Make sure that the ball does not move off of the screen before bouncing off of the right and bottom sides of the window.
The file KeyboardControl.java uses keyboard events to echo what characters are typed with the keyboard like we created in class. Download the file and modify it to draw a rectangle that moves based on presses of the arrow keys by doing the following:
Combine the bouncing ball and keyboard controlled rectangle to create a simple one-player version of Pong. If you have never played pong, it is a game with a ball bouncing around the screen. The player controls a paddle that the ball can bounce off of but can only move along one edge. The goal is to prevent the ball from getting past the paddle.