Eclipse IDE
For the week of Jan 30-Feb 3, 2006
Up until now, we've been focusing on simple text editors for Java. There are other
editors that are specially designed to help the programming process. These advanced
editors often fall under the category of IDE, or Integrated Development Enviroment.
Eclipse is one such IDE which helps you by coloring your text and allowing you to
auto-complete what you type, among other things.
Additional Information
If you would like, you may download Eclipse for your Windows machine at home from
Eclipse.org.
Procedure
- Start Eclipse by typing "
eclipse" at the command line.
- Accept (click OK) the default workspace suggestion.
- Close the "Welcome" window by clicking on the "x" on the "Welcome" tab.
- Create a project:
- File/New/Project/Java Project/Next
- Give it the name "Craps".
- Under "JDK Compliance" click "configure default".
- Select compiler compliance level 5.0.
- Click Apply, then Yes (to rebuild), then OK.
- Click Finish.
- You should now be in the "Java Perspective". There should be several
window panes, and in the upper right corner should be a small box with "Java"
in it. If you aren't in the "Java Perspective", you can get there by selecting
Window/Open Perspective/Java.
- Import an existing source file:
- File/Import/File System/Next
- Browse to /afs/cats/courses/cmps012a-cm/eclipse then click Choose. (Or you may download
Craps.java here--right click on the link and choose Save)
- Click on the eclipse folder icon then select Craps.java in the right hand pane.
- If the "Into folder" doesn't already show "Craps" then click on the browse
button for that field and select "Craps" then click OK.
- Click Finish.
- Open Craps.java in an editor.
- Click the "+" next to Craps in the Package Explorer (left pane), then click
the "+" on "(default package)" then double click Craps.java. An editor pane
should open with Craps.java. (Note that on some platforms the "+" will appear
instead as a small triangle.)
- Fix two problems in Craps.java indicated by the red circle with an "x" indicating
an error and a yellow circle (if you look close I believe it is a yellow light bulb)
indicating that Eclipse has a suggestion as to how to solve the problem.
- Scoll down to the first light bulb (yellow blob) in the left margin of the
editor pane. Notice the little red squares on the right margin of the editor
pane. They show where the errors are in the complete file. Try clicking on one.
- Click ONCE on the first light bulb. Give it a few seconds. It will show several
suggestions.
- Select the one suggesting you need to import java.util.Random, then double
click it. This will make the insertion for you.
- Scroll down to the next light bulb. (Look for the one remaining red square in the
right margin.) Click on the light bulb. Notice it shows you the methods that could
be called. Select the correct one and then double click it.
- Save the file and you should no longer see any red circles with white "x"s in them.
- Run the program.
- Select Run then Run...
- Select "Java Application" then click New.
- In the name field put: Craps
- If "Main class:" isn't already Craps, type it in or click Search... and select Craps.
- Click "Run".
- A console will appear. It may take a few seconds to get started. The console
should eventually show a prompt for the seed. You may need to click in the console
pane before you can enter any input.
- Play a few rounds of the game then end by betting 0.
- Add a new method using refactoring.
- In the method rollDiceUntilWinOrLose, select the lines after the comment
"// roll until point or 7" up through the end of the if-else statement. You
can get there quickly by clicking on the method name in the rightmost pane
labelled "Outline".
- Click menu Refactor and select Extract Method.
- Give the method a name. I suggest, rollUntilPointOr7.
- Click the "default" Access Modifier button then click OK.
- Notice how it figured out what needed to be passed in and that the result
needed to be assigned to variable winLose.
- Click File/Save. (If Save is not available then the file was already saved
automatically.)
- Try out the debugger.
- Click menu Run then Debug Last Launched.
- Scoll the Craps.java pane until you see the while loop in main.
- Set a break point by double clicking in the left margin next to the line
declaring "boolean won". A small blue check and ball (or something - I can't
be sure what it is :-) will appear in the margin.
- Click in the console window and enter a seed and an initial bet. This
should bring you to the break point.m (Click "Yes" when it asks to go to the
debug perspective. You can have it remember this answer if you wish.)
- Notice all of the local variables are displayed in the Variables pane.
- Try some of the various continue options (continue, step-into, step-over).
They are the icons along the top of the pane labelled "Debug". If you point
the mouse at one without clicking and wait a few seconds, a text descriptor
will pop-up.
- When you are done either end the game normally by betting 0, or click
the terminate icon (red square), and return to the "Java Perspective" by
clicking to the left of the "Debug" in the upper left corner, or select
Window/Open Perspective/Java.
- See some more name completion in action.
- Create another file just to play around with typing. File/New/Class. Call
it "Fiddle" or whatever you want. Check the box saying you want it to create a
main method. Click Finish.
- In the body of main type "String str;"
- On the next line type "str." then just wait. A window will pop-up showing
all of the possible operations you can perform on a string. Type a little more
so you have "str.subs". Notice how it just shows those methods or operations that
could fit with what you have typed.
|