Java Reference
In-Depth Information
Using the Interactions history, resetting the Interactions Pane
DrJava keeps a history of lines that you have typed in the Interactions Pane.
Use the up- and down-arrow keys to scroll through them.
You can remove all variables that have been declared and start afresh by
pressing button Reset , in the upper right of the window. Hitting Reset does not
destroy the Interactions history; it just removes all traces of execution.
Using classes from the Java APIs
If you want to use a class from one of the API packages, you have to import
it. Import statements can be typed in the Interactions Pane. For example, type the
following lines into Java (hitting return after each one), and you will see a win-
dow for the JFrame appear in the upper left corner of your monitor. You may
have to resize the window to make it big enough to see the title in its title bar:
import javax.swing.*;
JFrame jf= new JFrame("First JFrame");
jf.show();
Method calls in the Interactions Pane
Click “New”. This creates a new document, initially called (Untitled) . In
the Definitions Pane, type this class, which has one instance function and one
static function:
public class Test {
/** = the value 5 */
public static int testInstance() {
return 5;
}
/** = the value 6 */
public static int testStatic() {
return 6;
}
}
Save the file with name Test.java . After the file is saved, click button
Compile All . DrJava will compile the program. When it says “Last compilation
completed successfully”, click the Interactions tab and, in the Interactions Pane,
type this expression and then hit return:
Test.testStatic()
This expression is a call to function testStatic in class Test , and you can see
that it prints the value 6 , as required by its specification.
Function testInstance is an instance function, so it belongs in each folder
of class Test . Before we can call it, we have to have a folder. Type the follow-
ing lines into the Interactions pane:
 
Search WWH ::




Custom Search