|
Setting Up and Using BlueJ
CSE 142/143
|
Initial Set-Up
When you first start using BlueJ to develop your own classes, you should go
through the following steps to set up a BlueJ project in which to work.
The initial set-up is different depending on whether you're working in the IPL
or some other UW computer lab, or if you're working on your own machine.
- If you're using the IPL or some other UW computer lab, you'll want to put
all your work on a floppy disk, in drive A:.
- Insert a floppy disk and open it (e.g. by double-clicking on My
Computer and then double-clicking on A:). You may have to format the disk
at this point if it is brand new and unformatted.
- Run BlueJ (you can get this in the IPL from the Start menu, or
in the CRC from the Start menu, under Programs>CSE BlueJ>Start
BlueJ, or by double-clicking on C:\cse\tools\bluej\bluej.bat). A
blank shell window will open up, then a little BlueJ pop up, then
finally the main BlueJ window.
- Select Project>New Project, then select A: from the "Look
in:" drop-down menu, then type in "MyProject" (or
whatever project name you like) into the
"File name:" area, then select Create (or hit return). (This
will create a folder named MyProject in A:, and put in some magic BlueJ
files. It also will automatically open the new project.)
- Quit BlueJ, for instance by selecting File>Quit.
If you're working at home, you can put all your files on a floppy disk (in
which case you can follow the same instructions as the ones above), or you
can put your work somewhere on your hard drive, e.g. the same directory
where you installed all your CSE 142/143 software. In that case, follow the
instructions above, but wherever A: appears above, substitute C:\CSE (or
wherever you put installed your CSE software).
- When you start up BlueJ, it first creates a shell window, and then creates
its the main BlueJ window. The shell window will never be used.
You can simply minimize it (by clicking the _ in the title bar) to get it out of the way.
- If you're working
at home, and you get tired of minimizing the shell window each time you run BlueJ, you can
find the bluej.bat file that you installed, create a shortcut (e.g., doing
right-click and then selecting Create Shortcut and then renaming the
resulting shortcut to something nicer, like "Run BlueJ"),
right-click on the shortcut's icon and select Properties, select the Shortcut
tab (it's probably already selected), then change the Run: option
from Normal window to Minimized, then click OK. To run
BlueJ, click on the shortcut (not the original bluej.bat file), and BlueJ
should start up without popping up that annoying empty window each time.
Writing a Class
To define a new class:
- Run BlueJ (if it's not already running).
- Open your classes project (if it's not already open), by selecting
Project>Open Project, then finding and opening A:\classes,
C:\CSE\classes, or wherever you created your project.
- Click on New Class, then enter the name of the class to create, and hit
return (or OK). A new box labeled with your chosen class name should appear
in the project window.
- Double-click on the box representing your class. A text editor window
appears, containing an initial skeleton of the source code for your
class. Delete all this skeleton code, and write the class you want.
- Click the Compile button on the editor window. If you wrote your
class correctly, then you should eventually see "Class compiled - no
syntax errors" in the message window at the bottom. Otherwise, you'll
get some sort of errors. Fix them, and retry hitting the Compile button
until no more errors remain. If you have to quit working before things
compile successfully, then you can select Class>Save to save your program
(hitting the Compile button also saves your source file); later you
can restart BlueJ, reopen your project, and reopen your class source file to
continue working.
After you've gotten your class to compile, you're now set to try using your
class. Congratulations!
Using a New Compiled Class
You can use BlueJ's own graphical methods to create instances of the classes
you've written (right-click on the class box to see a list of constructors you
can invoke, and select one) and then to send
those instances messages (right-click on the instance box that appeared when you
instantiated the class, and select a message to send).
More flexibly, you can use Jeva to create instances of your new classes and send them
messages. First, you
need to put a copy of the right jeva-14x .bat file into your
BlueJ project directory (e.g. A:\MyProject or C:\CSE\MyProject). Here are some links you can download the .bat
file from: jeva-142.bat OR
jeva-143.bat
(Unix and Mac users can download the corresponding .sh files from the Computing
At Home web page). If you're using your home machine, and you
didn't put your uwcse .jar file into the C:\CSE\lib directory, then you
should edit the .bat files you just downloaded and change the ABSLIB14x
definition to be the directory where you installed your uwcse .jar file.
To run Jeva, double-click on jeva-14x .bat to start Jeva. (You don't need to quit
BlueJ; you can run both BlueJ and Jeva at the same time.) Then you should
be able to evaluate Java expressions and statements, and you should also be able
to create instances of your new BlueJ-produced classes and send messages to the instances. If you want to make changes
to your class, e.g. to fix a bug or add new methods or constructors, then do the
following steps:
- Quit Jeva.
- Go back to BlueJ, edit the class's source file, and try recompiling the
class. Repeat the edit-compile cycle until the class compiles
successfully.
- Restart
Jeva (by double-clicking on the Jeva .bat file in your BlueJ project
directory) and start working using the new version of the class.