Editing in JBuilder


Entering the Program

Within the Mult.java sub window, enter (and personalize) the following Java source program:

/* Mult.java demonstrates basic I/O in Java.
 * Author: Jane Doe.
 * Date: 2/29/99.
 * Purpose: Lab 1 in CS-1 at the University of Gallifrey.
 * Specification:
 *   Input(keyboard): aNumber, an integer;
 *   Output(screen): 2x, 4x and 8x aNumber.

import ann.easyio.*;

public class Mult 
	static Keyboard theKeyboard = new Keyboard();
	static Screen theScreen = new Screen();

	public static void main(String args[]) 

   		// 0. print a message explaining the purpose of the program.
		theScreen.println("\nThis program inputs a integer"
			+ "\n\tand displays 2x, 4x, and 8x its value.");

		// 1a. ask the user to enter an integer.
		theScreen.print("\nPlease enter an integer: ");
		// 1b.declare an integer container to hold the input number
		int aNumber;
		// 1c. input an integer, storing it in variable aNumber.
		aNumber = theKeyboard.readInt();

		// 2. output 2x, 4x and 8x aNumber.
		theScreen.print("\n\nTwice " + aNumber + " is "
			+ 2*aNumber
			+ ",\n\tand four times is "
			+ 4*aNumber
			+ ",\n\tand eight times is "
			+ 8*aNumber
			+ "\n\n");

One shortcut is to copy-and-paste the text above from your browser's window into the Mult.java window. Let's learn how to do this next.

In Windows, a block of text can be selected by pointing the mouse at the top of the block of text, and dragging downward to the bottom of the block of text. To copy-and-paste the selected text:

  1. Choose Edit -> Copy from the Edit menu You can alternatively use the keyboard shortcut cntrl-c (hold down the cntrl key and type c) to copy whatever you have selected.
  2. Move the mouse to the window in which you want to paste the text, and position the mouse cursor (i.e., click) where you want the text to be inserted.
  3. Choose Edit -> Paste from the Edit menu of the window in which you want to paste. You can alternatively use the keyboard shortcut cntrl-v to paste whatever you most recently copied.

Using this approach, copy the program shown above into the Mult.java sub window.


Personalizing the Program

As given above, Mult.java is the work of a fictitious person (Jane Doe) on a fictitious date (February 29, 1999), in a fictitious course (CS-1) at a fictitious university (the University of Gallifrey). Edit the program's opening comment (the part between the /* and */ symbols) as appropriate to make it your work on the current date, in your course at your university.

As you've probably figured out, you can use the mouse to position the cursor at an arbitrary point by pointing at that point and clicking the left mouse button. The arrow keys (or the mouse) can be used to reposition the cursor.

If you mistype something, it can be erased using the delete (or backspace) key. On many keyboards, the Delete key is set up to erase whatever is to the right of the cursor, while backspace erases whatever is to the cursor's left.

If you make a mistake, you can always undo your most recent typing using the undo command: Ctrl-z or by using the Edit -> Undo menu choice.

Saving Your Work.

When the Mult.java sub window contains the Mult.java program, you can store this program in a file by choosing File -> Save. If you look in the your project folder, you will see that it is no longer empty, but now contains many different files and folders. Most of these are just administrative files JBuilder uses to keep track of what is where.


Back to the Lab

Back to the Table of Contents

Back to the Introduction

Copyright 2000 by Prentice Hall. All rights reserved.