In this lab you will do your first actual java programming, creating
objects and calling methods. You will contine to get used to the Unix
computing environment. A considerable part of this lab is spent in
getting used to the tools you will use to write and build your program.
- Learn how to use emacs (and the jde) as an easy way to
develop java programs without the added weight of an IDE
- Create objects in Java.
- Call methods in Java.
- use implicit and explicit parameters.
- compile, debug and run a small Java application.
In this lab you will take preexisting files and finish them to create a
bouncing ball in a window. When you are finished, your
like this when you run it:
Copying the files
and then unzip the files
This has created a folder called lab2 in your home folder.
the lab2 folder your working folder (using the cd command appropriately
as you learned in the last lab) Then see what files are there using the
Start using xemacs
xemacs is best used either on campus, or from a genuine highspeed
connection (not the cable modem that is heavily used by everyone else
on the street)
One of the files that you just unzipped is named Lab2.java.
This is the file that you will need to work on. So open this file using
xemacs. From the command line type:
xemacs Lab2.java &
This may take a few seconds to come up fully. There is some
configuration for using java that gets done when starting emacs. From
off campus emacs may take as long as a minute to startup. You should
see something like the following:
You see that the file is nicely "pretty printed" with comments in blue,
java keywords in a a sort of pale purple and so on. Emacs will
also help you to indent your code later on when you are writing more
This file happens to be the main file for your application. You'll see
the "public static void main(String args)" which your book correctly
tells you that any application
The program runs as it is, it just doesn't do anything at all. Before
run any program, we must compile it.
Right now the java interface with xemacs is not working well. So go
back to your command line. (making sure you are in the Lab2 directory)
to complile all the java files in the directory. You can also put a specific java file on the command such as
if you only want to try compiling one file at a time.
Running the program.
Once again, the jde menu has some problems on this system right now
(I've got a ticket in with the IT folks), so I reccomend the following.
Go to your command window (the
one you ran emacs from) and run the program directly.
when you run a java application, you use the java command and the name
of the class which contains that funny public static void main method.
In our case that is the Lab2 class.
When you first run the program without doing anything, you will see
that you get your command prompt back after about a second without the
computer doing anything. thats ok, you need to write the program now.
Later on when you run the program and it shows the window,
You may get a warning about a font, this is only a warning and the font
will just look a little ugly.
Congradulations, you are now ready to begin writing your part of the
Writing Java code.
In order to make your Bouncing ball appear, you must create a Bouncer
object and call two methods on it. All of your code should be
placed in the
method of the Lab2 class. You will find
two lines of comments that read:
//put all of your code here in this method
//the method end on the next line so you need your code above here.
Put all of your code between these two lines of comments.
You need to
- Create an object of type Bouncer. (you don't need to import
anything for this class since it is one of the ones in the same
directory that you just unzipped. The constructor takes no parameters.
- Call the showBouncer method on your Bouncer object. This method takes no explicit parameters.
- Call the bounce method on your Bouncer object. This method takes
one explicit parameter, a whole number which is the speed of the ball.
Experiment with difference values for this parameter and submit your
lab with the ball taking between 1 and 2 seconds to get from the left
edge of the window to the right edge.
When you have created the object and called the two methods on it,
compile your program again, fix any errors in compiling and then run the program again. If you see the moving blue ball from the
first image above, you are done the program.
To submit your program, zip up the entire lab2 folder (as you zipped
the lab1 folder last time). Call your zip file
<your last name>Lab2.zip
so for example I would need to name my zip file santoreLab2.zip.
If you don't remember you might try
zip -r <your last name>Lab2.zip Lab2
Submit using the same proceedure as last time:
Submit it outside of class on your own this time.
This lab is due:
For the Monday/Wednesday class: Tuesday Oct 2nd at 11:59pm
For the Tuesday/Thursday class: Wednesday Oct 3rd at 11:59pm