Exercise 1: Editing Source Code

To give you a feel for working with the source editor, you will enter code in the Blink.java file to bounce the words up and down.

If you haven't yet created the Blink project, you should do so now using the instructions in Creating the Blink Project.

  1. Check the Java WorkShop Project Manager window for the name of the current project.
    If the current project is not Blink, double-click on the Blink project name.
  2. Type the lines of source code below.
    This code intentionally has errors in it because the next lesson shows you how to fix the errors.

    You can go to a specific line number by choosing Edit -> Go To Line. The line number of the pointer is shown on the right side of the footer.

    After line 17
    int speed;
    type:
    boolean offset;

    After line 25
    lbl = (att == null) ? "Blink" : att;
    type:
    offset = false;

    After lines 53-54
    g.setColor(Color.lightGray);
    }
    type:
    if offset
       y = y * 2;
    

    After line 57
    g.drawString(word, x, y);
    type:
    if (offset) {
       offset = false;
       y = y / 2
     } else {
        offset = true;
    }
    

  3. Click the Save button on the Edit/Debug toolbar.
    The path name of the saved file appears in the source editor footer.

Next lesson:

Exercise 2: Fixing Errors in a Build