Java Eyes
An introduction to your
Integrated Development Environment
(IDE)
Part 2: Editing a program
|
CSSE 120
Fundamentals of Software Development I
Rose-Hulman Institute of Technology
Computer Science & Software Engineering
Winter term, 2003-2004
|
|
Learning objectives:
After completing this project, you should:
|
Be able to: Explain the following concepts:
- Integrated Development Environment (IDE)
- Why using an IDE is valuable
- Compiling and executing a program
- Compile-time errors and run-time errors
- Documentation and Javadoc doc-comments
- Version control
- Why version control is valuable
|
Be able to: Do the following in our IDE (JCreator Pro and Tortoise CVS):
- Checkout and commit a project in the CVS version-control system
- Compile and execute a program
- Navigate the IDE
- Edit a program
- Use JDK Help to learn about a class
- Identify the apparent source of compile-time errors
- Provide Javadoc doc-comments per the course's documentation standard
|
Items in red are learning objectives for
this part of the project.
|
What you should do:
| What you should learn:
| Resources:
|
- Checkout your JavaEyes project.
|
- How to checkout a project
| How to checkout a CVS project by using Tortoise CVS
|
- Open your JavaEyes project.
|
| To open a project:
Click on the .jcw (JCreator Workspace) file in the project's folder.
|
- Locate the File View window.
- Question: How many Java files are in the JavaEyes project?
- Bring up the EyeBall.java file in the Class View window.
- Question: How many methods are in the EyeBall class?
- Question: How many fields are in the EyeBall class?
- Bring up the EyeBall.java file in the Editor window.
- Question: Who wrote the EyeBall class?
Important: Even though juicy bits of code are displayed
in your Editor window, the code is not the focus of today's exercise.
Do not feel compelled to read or understand the code at this point.
It is simply an example to help familiarize you with the IDE that you will use to develop Java software.
- Compile and execute the project and examine the output in the Output window.
- Question: What message appears first in the output window?
- Bring up the SquarePanel.java file in the Editor window.
Practice using the tabs in the Editor window to go back and forth between the code
for the EyeBall and SquarePanel classes.
- Use the ClassView menu of the EyeBall class to locate the getRadius method.
- Use the ClassView menu of the EyeBall class to locate the xPosition field.
- Question: Which approach seems easier
for finding a method of a class: using ClassView or scrolling through the class' text in the Editor?
- Locate the paintComponent method of the SquarePanel class.
- For each of the "What you should learn" items in the corresponding entry of the column to the right,
ask your partner: Do you understand [the item]?
Discuss and get help as needed.
This exercise continues below.
| Navigating the IDE
- Where to find the list of files in the project
- Where to find the list of methods and fields of a class in the project
- How to use ClassView to locate the methods and fields of a class in the project
- How to display the text (code) of a class in the project
- Where to find messages and console output from compiling or executing the project
| Navigating the IDE
-
The File View window
is the upper-left window, by default.
(You can drag it elsewhere if you wish.)
|
|
-
The Class View window
is the lower-left window, by default.
(You can drag it elsewhere if you wish.)
|
|
-
The Editor window
is the big window with the program's text (code).
It has tabs for each file that you have open for editing.
|
|
-
The Output window
is the bottom window, by default.
|
|
Messages from the compiler appear there,
as well as whatever is printed to the Console when the program runs.
- To recover a window that disappeared,
use the View ~ Toolbars menu.
Compiling and Executing
- Compile a project by any of:
- The Build ~ Compile Project menu
- The F7 key
- The Compile Project button:
- Execute a project by any of:
- The Build ~ Execute Project menu
- The F5 key
- The Execute Project button:
|
- Notice how different parts of the code are colored differently.
- Question: Why is color-coding valuable here?
- Question: For each item in row 1 of the following table,
draw a line to its corresponding item in row 2.
Comments | Keywords | Strings | Operators | Other
|
Black | Blue | Green | Purple | Red
|
- Briefly examine the Edit and
Search menus.
Most of the items on those menus
are probably familiar to you.
- Notice that the lines of code are numbered.
- Question: What is the first word on Line 78 of the JavaEyes class?
- Now learn how to edit (change) the program, as follows:
Find the declaration of the DEFAULT_EYE_COLOR field of the JavaEyes class:
public static final Color DEFAULT_EYE_COLOR = Color.white;
Change that line so that the eyes will be blue.
- The purpose of this part of the exercise is just to get you comfortable
using the tools, not to experiment with Java expressions and statements.
You'll do the latter in the next set of exercises.
- Compile and execute the project.
The eyes should now be blue. Cool, huh?
- Question: What happens if you make a change
and then execute the project without compiling it first?
- (Try it: change the color of the eyes to green but execute without compiling first.)
- You should have found that the new color change (to green) did not take effect.
Question: What is machine code,
and why is machine code relevant to this part of the exercise?
Compile and execute the project (so that the eyes are now green).
- If you wish, also try changing the color of the eyeballs.
- For each of the "What you should learn" items in the corresponding entry of the column to the right,
ask your partner: Do you understand [the item]?
Discuss and get help as needed.
This exercise continues below.
| Editing a project
- How to edit a program (i.e., change text in it)
- How editing and compiling interact
| Editing a project
- Most IDEs color-code the program's text.
- This helps the software developer visualize the syntax of Java statements.
- By default, JCreator automatically saves changes you made whenever you compile.
- So you never need to do File ~ Save.
- It is best to leave a "clean slate" when you exit a JCreator project. To do so:
- Window ~ Close All
- File ~ Close Workspace
- Java must be translated ("compiled") into machine code
before computers can process it.
The changes you make at the Java level are completely ignored by the computer
until you translate them into a language it can understand.
|
- Try setting the eye color to a less familiar color, e.g. sepia.
What happens? Can you guess why?
- Use JDK to find all the built-in names for colors.
- Hint: they are fields of the Color class.
Of course, you can define other colors,
but these are the only built-in colors.
- Change the eye color to a built-in color (pick one you find interesting!).
| Using JDK Help to learn about a class
- How to use JDK to locate the documentation for a class.
- How to find the description of the fields of a class.
| Using JDK Help to learn about a class
To use JDK to learn about a class:
- Select Help ~ JDK Help.
- A window labelled JavaDocs should open.
If not, ask an assistant for help. (It's easy to fix.)
- Under the Index tab, type the name of the class you want to learn about (e.g., Color)
and press the Display button.
- The document in the window that opens says lots about the class.
In particular, there are links at the top to the class' Fields,
Constructors and Methoss.
|
- Change the label of the Quit button to a string of your own choosing.
Compile and execute, confirming tht your change worked as expected.
- Hint: find the place in JavaEyes.java (NOT QuitButton.java)
where a new Button is created.
- If you don't find it in a minute or less, just ask someone where it is.
More Practice at Navigating and Editing in your IDE
|  
|
- Checkin your JavaEyes project, tagging it
Stage2
spelled just like that.
|
- How to checkin a project (update, add contents, commit, tag)
- What checking out a project accomplishes
- What checking in a project accomplishes
- Why version control is useful
| How to checkin a project
(update, add contents, commit and tag)
by using Tortoise CVS
|
Summary
- Question:
How do you open the Code Editing window, if it is not already open?
- Question:
How do you find out details about JDK classes and methods?
- Question:
List five colors that are built into Java.
- You are NOT expected to remember the colors, of course,
but you ARE expected to remember how to look them up!
- Knowing how to learn is
more important than what you know.
- Question:
How much time did you spend on Part 2 of JavaEyes?
|  
|  
|
- Close your JavaEyes project in the proper fashion.
|
| To close a project:
It is best to leave a "clean slate" when you exit a JCreator project. To do so:
- Window ~ Close All
- File ~ Save Workspace
- File ~ Close Workspace
| |